From: Elia Pinto <gitter.spiros@gmail.com>
To: git@vger.kernel.org
Cc: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Elia Pinto" <gitter.spiros@gmail.com>,
"Hamza Mahfooz" <someguy@effective-light.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Patrick Steinhardt" <ps@pks.im>,
"Phillip Wood" <phillip.wood@dunelm.org.uk>
Subject: [PATCH 0/2] grep, diff: do not silently truncate sizes of 4GiB or more
Date: Sun, 1 Nov 2026 09:44:55 +0100 [thread overview]
Message-ID: <cover.1793521916.git.gitter.spiros@gmail.com> (raw)
This series continues the search for truncated sizes on platforms where
"long" is 32 bits but size_t is 64 bits (64-bit Windows). This time it
covers grep and diff, where a file of 4GiB or more produced wrong
results without any error.
- 1/2 grep: on the working tree and --no-index, it silently missed
matches beyond the truncated size. Now it uses size_t and works,
for blobs too.
- 2/2 diff: on the working tree, textconv, --no-index and combine-diff,
it produced a diff of a prefix, and a patch that truncates the file
when applied (as git add -p does). Now it dies with a clear error,
like the blob side already did.
Of the remaining -Wshorten-64-to-32 warnings in the diff and grep code,
these are the only reachable ones. The others are in xdiff internals
(inputs limited to MAX_XDIFF_SIZE, 1023MiB), in buffer_is_binary()
(which looks at 8000 bytes), or in places where the size can't exceed
4GiB. Widening diff_filespec.size to size_t, so that diff actually works
above 4GiB, is a much bigger change, left for later.
No tests, as they would need 4GiB of input on such a platform. Both
effects were verified by simulating the truncation at 16 bits, and the
commit messages give the details.
It doesn't depend on the other series in flight and merges cleanly with
them. Based on master 50fe5cc63f.
Elia Pinto (2):
grep: use size_t for the size of buffers to search
diff: die instead of truncating sizes of 4GiB or more
combine-diff.c | 11 +++++++----
diff-no-index.c | 2 +-
diff.c | 8 ++++----
grep.c | 16 ++++++++--------
grep.h | 4 ++--
5 files changed, 22 insertions(+), 19 deletions(-)
base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
--
2.53.0
next reply other threads:[~2026-11-01 8:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 8:44 Elia Pinto [this message]
2026-11-01 8:44 ` [PATCH 1/2] grep: use size_t for the size of buffers to search Elia Pinto
2026-11-01 8:44 ` [PATCH 2/2] diff: die instead of truncating sizes of 4GiB or more Elia Pinto
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=cover.1793521916.git.gitter.spiros@gmail.com \
--to=gitter.spiros@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
--cc=someguy@effective-light.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