[PATCH 3/3] diffcore-delta: use size_t for the size of the buffer to hash
- From
Elia Pinto <gitter.spiros@gmail.com>
- Date
- Nov 1, 2026, 15:36 UTC
- Message-ID
- <0c5442280cc441ffa3ed61af74466e2b4d2d6794.1793546752.git.gitter.spiros@gmail.com>
- In-Reply-To
- <cover.1793546752.git.gitter.spiros@gmail.com>
hash_chars() in diffcore-delta.c takes the buffer size as an "unsigned int". With a file of 4GiB or more, it hashes only a prefix; because the similarity score is calculated against the full size, similarity is undervalued, so true renames are missed, which also affects "git log --follow" and merges.
This was verified using a 16-bit simulation, where "git diff --cached -M" reported a delete and add instead of a rename (e.g., "D a" and "A b" instead of "R099 a b").
Make the size variable "size_t".
Triggering this requires processing a file of 4GiB or more, so no test is added.
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com> --- diffcore-delta.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/diffcore-delta.c b/diffcore-delta.c index 2b7db39983..7f10f79ffe 100644 --- a/diffcore-delta.c +++ b/diffcore-delta.c @@ -127,7 +127,7 @@ static struct spanhash_top *hash_chars(struct repository *r, unsigned int accum1, accum2, hashval; struct spanhash_top *hash; unsigned char *buf = one->data; - unsigned int sz = one->size; + size_t sz = one->size; int is_text = !diff_filespec_is_binary(r, one); i = INITIAL_HASH_SIZE;
-- 2.53.0