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

Re: corrupt object memory allocation error

From
Jeff King <peff@peff.net>
Date
Nov 20, 2013, 21:33 UTC
Message-ID
<20131120213348.GA29004@sigill.intra.peff.net>
In-Reply-To
<20131120203350.GA31139@kitenet.net>
On Wed, Nov 20, 2013 at 04:33:50PM -0400, Joey Hess wrote:
Show 14 quoted lines
> I've got a git repository of < 2 mb, where git wants to
> allocate a rather insane amount of memory:
> 
> >git fsck
> Checking object directories: 100% (256/256), done.
> fatal: Out of memory, malloc failed (tried to allocate 124865231165 bytes)
> 
> > git show 11644b5a075dc1425e01fbba51c045cea2d0c408
> fatal: Out of memory, malloc failed (tried to allocate 124865231165 bytes)
> 
> The problem seems to be the attached object file, which has gotten
> corrupted, presumably in the header that git reads to see how large it
> is. Thought I'd report this in case there is some easy way to
> add a sanity check.

Definitely a corrupt object. The start is not a valid zlib header, so we guess that it is an "experimental loose object". This is a format that git wrote for very short period as a performance experiment; it didn't pan out and we no longer write it.

The loose object format contains the (purported) object size outside of the checksum'd zlib data (whereas the normal format has a human-readable header that gets zlib'd). Your corrupted bytes end up specifying a ridiculously large size.

I wonder if it is time to drop reading support for the experimental objects. It was never widely used, and was deprecated in v1.5.2 by 726f852 (deprecate the new loose object header format, 2007-05-09). That would improve the case when the initial bytes of a loose object are corrupted, because we would complain about the bogus zlib data before trying to allocate the buffer.

The problem would still remain for packfiles, which use a similar encoding, but I suspect it is less common there. For a single-byte corruption, it is unlikely to be right in the length header. But for absolute junk that is not git data at all, the first bytes are very likely to be corrupted. In the pack case, we would notice early that it does not look like a packfile; for the loose object, we have no such header and proceed with the allocation.

As for your specific corruption, I can't make heads or tails of it. It is not a single-bit error. The first two bytes of a loose object should always be <0x78, 0x01>, which is the standard zlib deflate header. Your bytes aren't even close, and decoding the rest with a corrupted zlib header seems fruitless.

You don't happen to have another copy of the object (or of the data contained in the object, such as the working tree file), do you? It might be interesting to see a comparison of the bytes of the correct data and your corruption.

-Peff
Previous: Joey HessNext: Joey Hess
Message 2 of 28 in “corrupt object memory allocation error”
  1. Joey HessNov 20, 2013
  2. Jeff KingNov 20, 2013
  3. Joey HessNov 20, 2013
  4. drop support for "experimental" loose objectsJeff King, Nov 21, 2013
  5. Jeff KingNov 21, 2013
  6. Duy NguyenNov 21, 2013
  7. Keshav KiniNov 21, 2013
  8. Jeff KingNov 21, 2013
  9. Junio C HamanoNov 21, 2013
  10. Jonathan NiederNov 23, 2013
  11. Jeff KingNov 23, 2013
  12. Jonathan NiederNov 23, 2013
  13. Joey HessNov 21, 2013
  14. Christian CouderNov 21, 2013
  15. Jeff KingNov 22, 2013
  16. Christian CouderNov 22, 2013
  17. Jeff KingNov 22, 2013
  18. Christian CouderNov 22, 2013
  19. Jeff KingNov 22, 2013
  20. Junio C HamanoNov 22, 2013
  21. Jeff KingNov 22, 2013
  22. Joey HessNov 22, 2013
  23. Jeff KingNov 24, 2013
  24. Jeff KingNov 24, 2013
  25. Junio C HamanoNov 25, 2013
  26. Jeff KingNov 27, 2013
  27. Junio C HamanoNov 27, 2013
  28. Jeff KingNov 27, 2013

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.