git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Elia Pinto
Message 4 of 4 in “use size_t for a few sizes that are 32 bits everywhere”
  1. 0/3 use size_t for a few sizes that are 32 bits everywhereElia Pinto, Nov 1, 2026
  2. 1/3 csum-file: use size_t for the count passed to hashwrite()Elia Pinto, Nov 1, 2026
  3. 2/3 diff: use size_t for the size passed to count_lines()Elia Pinto, Nov 1, 2026
  4. 3/3 diffcore-delta: use size_t for the size of the buffer to hashElia Pinto, Nov 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.