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

Re: heads-up: git-index-pack in "next" is broken

From
Nicolas Pitre <nico@cam.org>
Date
Oct 17, 2006, 21:21 UTC
Message-ID
<Pine.LNX.4.64.0610171706260.1971@xanadu.home>
In-Reply-To
<Pine.LNX.4.64.0610171339030.3962@g5.osdl.org>
On Tue, 17 Oct 2006, Linus Torvalds wrote:
Show 11 quoted lines
> 
> 
> On Tue, 17 Oct 2006, Nicolas Pitre wrote:
> > On Tue, 17 Oct 2006, Sergey Vlasov wrote:
> > > 
> > > Yes, on x86_64 this is 24 because of 8-byte alignment for longs:
> > 
> > Ah bummer.  Then this is most likely the cause.  And here's a simple 
> > fix (Junio please confirm):
> 
> Why do you use "unsigned long" in the first place?

Because offsets into packs are expressed as unsigned long everywhere else (except in the current pack index on-disk format).

> For some structure like this, it sounds positively wrong. Pack-files 
> should be architecture-neutral, which means that they shouldn't depend on 
> word-size, and they should be in some neutral byte-order.
But they do.  Please consider this code:
	case OBJ_OFS_DELTA:
		memset(delta_base, 0, sizeof(*delta_base));
		c = pack_base[pos++];
		base_offset = c & 127;
		while (c & 128) {
			base_offset += 1;
			if (!base_offset || base_offset & ~(~0UL >> 7))
				bad_object(offset, "offset value overflow for delta base object");
			if (pos >= pack_limit)
				bad_object(offset, "object extends past end of pack");
			c = pack_base[pos++];
			base_offset = (base_offset << 7) + (c & 127);
		}
		delta_base->offset = offset - base_offset;
		if (delta_base->offset >= offset)
			bad_object(offset, "delta base offset is out of bound");
		break;

Do you see anything inerently wrong in this code? The above is already 64-bit ready such that it'll just work on 64-bit archs and will display a sensible message if a 32-bit arch encounter a pack larger than 4GB. But the on-disk pack format has no limitation what so ever.

> Quite frankly, this all makes me go "Eww..". The original pack-file (well, 
> v2) format was well-defined and had none of these issues. In contrast, the 
> new code in 'next' is just _ugly_.
I beg to differ.  Please reconsider in light of the above.
Show 11 quoted lines
> And maybe it's just me, but I consider unions to be bug-prone on their 
> own. The "master" branch has exactly two unions: the "grep_expr" structure 
> contains one (where the union member is clearly defined by the node type 
> in that structure), and object.c has a "union any_object" that _literally_ 
> exists as purely an allocation size issue (ie it is used _only_ to 
> allocate the maximum size of any of the possible structures).
> 
> In contrast, the new union introduced in "next" is just horrid. There's 
> not even any way to know which member to use, except apparently that it 
> expects that a SHA1 is never zero in the last 12 bytes. Which is probably 
> true, but still - that's some ugly stuff.

This union should be looked at just like a sortable hash pointing to a base object so that deltas with the same base object can be sorted together. And the field to use is well defined of course: deltas with sha1 to base use the sha1 member, deltas with offset to base use the offset member. This hash, together with the delta type, constitute a tuple guaranteed to be unique so there can't be any confusion.

> Is this something you want to bet a big project on?
I don't see why not.
Nicolas
Previous: Linus TorvaldsNext: Linus Torvalds
Message 12 of 33 in “heads-up: git-index-pack in "next" is broken”
  1. Junio C HamanoOct 17, 2006
  2. Nicolas PitreOct 17, 2006
  3. Junio C HamanoOct 17, 2006
  4. Nicolas PitreOct 17, 2006
  5. Junio C HamanoOct 17, 2006
  6. Nicolas PitreOct 17, 2006
  7. Sergey VlasovOct 17, 2006
  8. Junio C HamanoOct 17, 2006
  9. Nicolas PitreOct 17, 2006
  10. Nicolas PitreOct 17, 2006
  11. Linus TorvaldsOct 17, 2006
  12. Nicolas PitreOct 17, 2006
  13. Linus TorvaldsOct 17, 2006
  14. Nicolas PitreOct 18, 2006
  15. Linus TorvaldsOct 18, 2006
  16. Nicolas PitreOct 18, 2006
  17. Linus TorvaldsOct 18, 2006
  18. Davide LibenziOct 18, 2006
  19. Linus TorvaldsOct 18, 2006
  20. Davide LibenziOct 18, 2006
  21. Linus TorvaldsOct 18, 2006
  22. Davide LibenziOct 18, 2006
  23. Linus TorvaldsOct 18, 2006
  24. Davide LibenziOct 18, 2006
  25. Junio C HamanoOct 18, 2006
  26. Nicolas PitreOct 18, 2006
  27. Junio C HamanoOct 18, 2006
  28. Junio C HamanoOct 18, 2006
  29. Johannes SchindelinOct 18, 2006
  30. Nicolas PitreOct 18, 2006
  31. Nicolas PitreOct 18, 2006
  32. Junio C HamanoOct 17, 2006
  33. Nicolas PitreOct 18, 2006

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.