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

Re: [PATCH v2 1/4] odb: use size_t for the length of objects to write

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Oct 31, 2026, 10:16 UTC
Message-ID
<20261031101619.172770-1-gitter.spiros@gmail.com>
In-Reply-To
<auSDFRHpLy65PMF_@pks.im>
On Fri, Oct 30, 2026 at 12:44:34PM +0100, Patrick Steinhardt wrote:
Show 19 quoted lines
> > diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
> > index 463b38f990..0a89bbb455 100755
> > --- a/t/t1007-hash-object.sh
> > +++ b/t/t1007-hash-object.sh
> > @@ -297,4 +297,17 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
> >  	test_cmp expect actual
> >  '
> >  
> > +test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
> > +		'write filtered files over 4GB correctly' '
> > +	{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
> > +	test_oid large5GB >expect &&
> > +	test_config filter.null-filter.clean "cat" &&
> > +	echo "big filter=null-filter" >.gitattributes &&
> > +	git hash-object -w -- big >actual &&
> > +	test_cmp expect actual &&
> > +	echo $((5*1024*1024*1024)) >expect &&
>
> Isn't this the exact same as `big`? So...

Ah, there was a slight misunderstanding here: `expect` didn't contain the content of `big`, but its expected size in bytes (`5368709120`), which was then compared against the output of `cat-file -s`.

That said, your point stands: checking only the size was a weak and redundant check. The OID printed by `hash-object -w` is computed directly from the object content that was written. If the length had been truncated (like on Windows), the written object would be different and its OID wouldn't match `large5GB`. I verified this by simulating the truncation: forcing the length to 32 bits in `odb_write_object_ext()` causes the test to fail right there on the OID comparison.

Because of this, `test_cmp big actual` isn't needed, and running it would unnecessarily cost another expensive read of 5 GiB from the object database.

Show 5 quoted lines
>
> > +	git cat-file -s $(cat actual) >actual &&
>
> We shouldn't read from and write to the same file. Maybe write it to
> "actual.size" instead?

Agreed, reading from and writing to the same file was fragile, even though it worked because shell redirection happens after expansion. In v3 this goes away completely since we dropped the size line.

>
> Also, it might make sense to use `test_cmp_bin ()` instead.

Since the size check is gone, we only compare the OID, which is text, so `test_cmp` remains the correct tool. `test_cmp_bin` would only make sense for comparing binary content, which we no longer do for the reasons mentioned above.

Instead, v3 checks that the object actually exists in the database by running `git cat-file -e "$(cat actual)"`. This is a cheap check that confirms `-w` wrote it successfully without needing to read back the 5 GiB content.

Thanks for the review! v3 will follow shortly in the same thread.
Elia
Previous: Patrick SteinhardtNext: Elia Pinto
Message 11 of 23 in “use size_t for a few more object and buffer sizes”
  1. 0/3 use size_t for a few more object and buffer sizesElia Pinto, Oct 21, 2026
  2. 1/3 odb: use size_t for the length of objects to writeElia Pinto, Oct 21, 2026
  3. Patrick SteinhardtOct 21, 2026
  4. 2/3 diff: use size_t for the allocation size of word-diff buffersElia Pinto, Oct 21, 2026
  5. Patrick SteinhardtOct 21, 2026
  6. 3/3 convert: use size_t for buffer sizesElia Pinto, Oct 21, 2026
  7. Patrick SteinhardtOct 21, 2026
  8. 0/4 use size_t for a few more object and buffer sizesElia Pinto, Oct 30, 2026
  9. 1/4 odb: use size_t for the length of objects to writeElia Pinto, Oct 30, 2026
  10. Patrick SteinhardtOct 30, 2026
  11. Elia PintoOct 31, 2026
  12. 2/4 diff: use size_t for the allocation size of word-diff buffersElia Pinto, Oct 30, 2026
  13. 3/4 convert: use size_t for buffer sizesElia Pinto, Oct 30, 2026
  14. 4/4 convert: use size_t for text statistics and ident countsElia Pinto, Oct 30, 2026
  15. Patrick SteinhardtOct 30, 2026
  16. Elia PintoOct 31, 2026
  17. Patrick SteinhardtNov 2, 2026
  18. Junio C HamanoNov 2, 2026
  19. 0/4 use size_t for a few more object and buffer sizesElia Pinto, Oct 31, 2026
  20. 1/4 odb: use size_t for the length of objects to writeElia Pinto, Oct 31, 2026
  21. 2/4 diff: use size_t for the allocation size of word-diff buffersElia Pinto, Oct 31, 2026
  22. 3/4 convert: use size_t for buffer sizesElia Pinto, Oct 31, 2026
  23. 4/4 convert: use size_t for text statistics and ident countsElia Pinto, Oct 31, 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.