Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Elia Pinto <gitter.spiros@gmail.com>
Cc: git@vger.kernel.org,  Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v2 3/4] diffcore-delta: use size_t for the size of the buffer to hash
Date: Tue, 17 Nov 2026 15:21:49 -0800	[thread overview]
Message-ID: <xmqq7bibavsi.fsf@gitster.g> (raw)
In-Reply-To: <3427c3d2c8c689371bcc111f0915853a0f679f5d.1794909894.git.gitter.spiros@gmail.com> (Elia Pinto's message of "Tue, 17 Nov 2026 11:37:55 +0100")

Elia Pinto <gitter.spiros@gmail.com> writes:

> 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;

The cnt member of spanhash is still uint, and can wrap down to 0
after 4 billion collisions and makes it appear the hash bucket is
empty.  Should it be widened at the same time, or are there reasons
why it does not need to (like hashval member that can stay uint)?

>  	int is_text = !diff_filespec_is_binary(r, one);
>  
>  	i = INITIAL_HASH_SIZE;

  reply	other threads:[~2026-11-17 23:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 15:36 [PATCH 0/3] use size_t for a few sizes that are 32 bits everywhere Elia Pinto
2026-11-01 15:36 ` [PATCH 1/3] csum-file: use size_t for the count passed to hashwrite() Elia Pinto
2026-11-01 15:36 ` [PATCH 2/3] diff: use size_t for the size passed to count_lines() Elia Pinto
2026-11-04 13:58   ` Phillip Wood
2026-11-04 15:45     ` Phillip Wood
2026-11-01 15:36 ` [PATCH 3/3] diffcore-delta: use size_t for the size of the buffer to hash Elia Pinto
2026-11-17 10:37 ` [PATCH v2 0/4] widen a few sizes and counts that are 32 bits everywhere Elia Pinto
2026-11-17 10:37   ` [PATCH v2 1/4] csum-file: use size_t for the count passed to hashwrite() Elia Pinto
2026-11-17 17:52     ` Junio C Hamano
2026-11-17 23:50       ` brian m. carlson
2026-11-17 10:37   ` [PATCH v2 2/4] diff: use size_t for sizes and line counts of complete rewrites Elia Pinto
2026-11-17 10:37   ` [PATCH v2 3/4] diffcore-delta: use size_t for the size of the buffer to hash Elia Pinto
2026-11-17 23:21     ` Junio C Hamano [this message]
2026-11-17 10:37   ` [PATCH v2 4/4] diff: use uintmax_t for diffstat totals and graph scaling Elia Pinto
2026-11-17 16:36     ` Torsten Bögershausen
2026-11-17 23:13     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7bibavsi.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitter.spiros@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox