Git development
 help / color / mirror / Atom feed
* [PATCH 0/2] grep, diff: do not silently truncate sizes of 4GiB or more
@ 2026-11-01  8:44 Elia Pinto
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Elia Pinto @ 2026-11-01  8:44 UTC (permalink / raw)
  To: git
  Cc: Johannes Schindelin, Elia Pinto, Hamza Mahfooz, Junio C Hamano,
	Ævar Arnfjörð Bjarmason, Patrick Steinhardt,
	Phillip Wood

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-01  8:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-01  8:44 [PATCH 0/2] grep, diff: do not silently truncate sizes of 4GiB or more Elia Pinto
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox