]> git.99rst.org Git - git.git/commit
pathspec: use match for sparse-index expansion checks
authorTed Nyman <redacted>
Mon, 20 Jul 2026 22:31:20 +0000 (15:31 -0700)
committerJunio C Hamano <redacted>
Tue, 21 Jul 2026 17:33:14 +0000 (10:33 -0700)
commitdd674df3267112248b0012ce614168055a416920
tree7a6068af5ace33d82ad0684e26d67551a8e38f11
parente9019fcafe0040228b8631c30f97ae1adb61bcdc
pathspec: use match for sparse-index expansion checks

The pathspec parser computes `len` and `nowildcard_len` from
`item.match`, which includes any prefix added when a command is run
from a subdirectory. `item.original` can still contain the shorter,
unprefixed argument.

Using `item.original + item.nowildcard_len` in
`pathspec_needs_expanded_index()` can therefore read past the end of
the allocation. AddressSanitizer reports a heap-buffer-overflow for
prefixed wildcard pathspecs passed to `git rm` and `git reset` with a
sparse index.

The mismatch dates back to 4d1cfc1351 ("reset: make --mixed
sparse-aware", 2021-11-29), which introduced the helper using
`item.original`. b29ad38322 ("pathspec.h: move
pathspec_needs_expanded_index() from reset.c to here", 2022-08-07)
later moved it to `pathspec.c` and preserved the affected comparisons.

Use `item.match` consistently when checking whether a pathspec can
match a sparse-directory entry. Add coverage for prefixed wildcard
pathspecs so both commands keep the index sparse.

Signed-off-by: Ted Nyman <redacted>
Reviewed-by: Taylor Blau <redacted>
Signed-off-by: Junio C Hamano <redacted>
pathspec.c
t/t1092-sparse-checkout-compatibility.sh
git clone https://git.99rst.org/PROJECT