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

Re: [PATCH 2/7] patch-delta: use size_t for sizes

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 15, 2026, 09:29 UTC
Message-ID
<03cc2127-7686-5d71-0e8e-aa2fccb78820@gmx.de>
In-Reply-To
<aibJTHKsmqe_EJHc@pks.im>
Hi Patrick,
On Mon, 15 Jun 2026, Patrick Steinhardt wrote:
Show 21 quoted lines
> On Thu, Jun 04, 2026 at 10:51:07AM +0000, Johannes Schindelin via GitGitGadget wrote:
> > From: Johannes Schindelin <johannes.schindelin@gmx.de>
> > 
> > `patch_delta()` takes the source and delta sizes by value and writes
> > back the reconstructed target size through an `unsigned long *`.  That
> > datatype cannot represent a value that exceeds 4 GiB on systems where
> > `unsigned long` is 32-bit (notably 64-bit Windows builds), though, even
> > though the delta encoding itself, the on-disk layout, and the in-memory
> > buffers happily carry such sizes. A `size_t` companion to
> > `get_delta_hdr_size()`, `get_delta_hdr_size_sz()`, was introduced in
> > 17fa077596 (delta, packfile: use size_t for delta header sizes,
> > 2026-05-08) precisely so that `patch_delta()` could be widened without
> > changing the on-the-wire decoding helper's signature.
> > 
> > Widen `patch_delta()`'s three size parameters to `size_t` and switch
> > its internal use of `get_delta_hdr_size()` to the `_sz` variant.
> > Then propagate the wider type through the callers.
> 
> Does `get_delta_hdr_size()` have any remaining callers after this patch
> series? I currently only spot two such callers, and you convert both of
> them in this patch.

As you noticed later on in the review: No, there are no such callers left, and the `_sz` variant gets renamed, concluding the incremental migration of that function from `unsigned long` to `size_t`.

> And can we reasonably add a test case that exercises this change?

Not reasonably, no. This would require constructing another artificial _large_ object, this time with an unpacked Git object with a size >=4GB that needs to be transmogrified into a different object.

Better leave the verification of this patch to static analysis (GCC or Clang have become quite good at spotting things like this; Coverity would be, too, if it ever comes back up from its "upgrades to the Scan servers", https://web.archive.org/web/20260516152422/https://scan.coverity.com/ seems to be the start date of this update).

Show 16 quoted lines
> 
> > diff --git a/packfile.c b/packfile.c
> > index 89366abfe3..e202f48837 100644
> > --- a/packfile.c
> > +++ b/packfile.c
> > @@ -1964,10 +1964,8 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
> >  			      (uintmax_t)curpos, p->pack_name);
> >  			data = NULL;
> >  		} else {
> > -			unsigned long sz;
> >  			data = patch_delta(base, base_size, delta_data,
> > -					   delta_size, &sz);
> > -			size = sz;
> > +					   delta_size, &size);
> 
> Nice that we get rid of this awkward construct.

Awkward, but necessary to allow for an incremental, reviewable conversion ;-)

Ciao, Johannes

Previous: Patrick SteinhardtNext: Johannes Schindelin via GitGitGadget
Message 5 of 29 in “More work supporting objects larger than 4GB on Windows”
  1. 0/7 More work supporting objects larger than 4GB on WindowsJohannes Schindelin via GitGitGadget, Jun 4, 2026
  2. 1/7 compat/msvc: use _chsize_s for ftruncateJohannes Schindelin via GitGitGadget, Jun 4, 2026
  3. 2/7 patch-delta: use size_t for sizesJohannes Schindelin via GitGitGadget, Jun 4, 2026
  4. Patrick SteinhardtJun 8, 2026
  5. Johannes SchindelinJun 15, 2026
  6. 3/7 pack-objects(check_pack_inflate()): use size_t instead of unsigned longJohannes Schindelin via GitGitGadget, Jun 4, 2026
  7. Patrick SteinhardtJun 8, 2026
  8. Johannes SchindelinJun 15, 2026
  9. 4/7 packfile: widen unpack_entry()'s size out-parameter to size_tJohannes Schindelin via GitGitGadget, Jun 4, 2026
  10. Patrick SteinhardtJun 8, 2026
  11. Johannes SchindelinJun 15, 2026
  12. 5/7 pack-objects: use size_t for in-core object sizesJohannes Schindelin via GitGitGadget, Jun 4, 2026
  13. 6/7 packfile,delta: drop the `cast_size_t_to_ulong()` wrappersJohannes Schindelin via GitGitGadget, Jun 4, 2026
  14. Patrick SteinhardtJun 8, 2026
  15. 7/7 odb: use size_t for object_info.sizep and the size APIsJohannes Schindelin via GitGitGadget, Jun 4, 2026
  16. Patrick SteinhardtJun 8, 2026
  17. Johannes SchindelinJun 15, 2026
  18. 0/7 More work supporting objects larger than 4GB on WindowsJohannes Schindelin via GitGitGadget, Jun 15, 2026
  19. 1/7 compat/msvc: use _chsize_s for ftruncateJohannes Schindelin via GitGitGadget, Jun 15, 2026
  20. 2/7 patch-delta: use size_t for sizesJohannes Schindelin via GitGitGadget, Jun 15, 2026
  21. Junio C HamanoJun 16, 2026
  22. 3/7 pack-objects(check_pack_inflate()): use size_t instead of unsigned longJohannes Schindelin via GitGitGadget, Jun 15, 2026
  23. 4/7 packfile: widen unpack_entry()'s size out-parameter to size_tJohannes Schindelin via GitGitGadget, Jun 15, 2026
  24. 5/7 pack-objects: use size_t for in-core object sizesJohannes Schindelin via GitGitGadget, Jun 15, 2026
  25. 6/7 packfile,delta: drop the `cast_size_t_to_ulong()` wrappersJohannes Schindelin via GitGitGadget, Jun 15, 2026
  26. 7/7 odb: use size_t for object_info.sizep and the size APIsJohannes Schindelin via GitGitGadget, Jun 15, 2026
  27. Junio C HamanoJun 15, 2026
  28. Patrick SteinhardtJun 18, 2026
  29. Junio C HamanoJun 18, 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.