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

Re: [PUB]corrupt repos does not return error with `git fsck`

From
Jeff King <peff@peff.net>
Date
May 20, 2015, 21:55 UTC
Message-ID
<20150520215547.GD8421@peff.net>
In-Reply-To
<xmqqlhgjm19z.fsf@gitster.dls.corp.google.com>
On Wed, May 20, 2015 at 01:39:36PM -0700, Junio C Hamano wrote:
Show 16 quoted lines
> Yeah, "bad object" sounds as if we tried to parse something that
> exists and it was corrupt.  So classifying "a file or a pack index
> entry exists where a valid object with that name should reside in"
> as "bad object" and "there is no such file or a pack index entry
> that would house the named object" as "missing object" _might_ make
> things better.
> 
> But let's think about it a bit more.  Would it have prevented the
> original confusion if we said "missing object"?  I have a feeling
> that it wouldn't have.  Faheem was so convinced that the object
> named with the 40-hex *must* exist in the cloned repository, and if
> we told "missing object" to such a person, it will just enforce the
> (mis)conception that the repository is somehow corrupt, when it is
> not.
> 
> So...

I dunno. If it were phrased not as "missing object" but as "there is no such object in the repository", then it seems more clear to me that the error is in the request, not in the repository (and hopefully the user would examine their assumption that it should be).

But "bad object" is just a horrible error message. It actively implies corruption. And I think if we do have corruption, then parse_object() already reports it. For example:

  # helpers
  objfile() {
    printf '.git/objects/%s' $(echo $1 | sed 's,..,&/,')
  }
  blob=$(echo content | git hash-object -w --stdin)
  # object with a sha1 mismatch
  mismatch=1234567890123456789012345678901234567890
  mkdir .git/objects/12
  cp $(objfile $blob) $(objfile $mismatch)
  # plain old missing object
  missing=1234abcdef1234abcdef1234abcdef1234abcdef
  # object with data corruption
  corrupt=$blob
  chmod +w $(objfile $corrupt)
  dd if=/dev/zero of=$(objfile $corrupt) bs=1 count=1 conv=notrunc seek=10
  # now show each
  for bad in corrupt mismatch missing; do
    echo "==> $bad"
    git --no-pager show $(eval "echo \$$bad")
  done
produces:
  ==> corrupt
  error: inflate: data stream error (invalid distance too far back)
  error: unable to unpack d95f3ad14dee633a758d2e331151e950dd13e4ed header
  error: inflate: data stream error (invalid distance too far back)
  fatal: loose object d95f3ad14dee633a758d2e331151e950dd13e4ed (stored in .git/objects/d9/5f3ad14dee633a758d2e331151e950dd13e4ed) is corrupt
  ==> mismatch
  error: sha1 mismatch 1234567890123456789012345678901234567890
  fatal: bad object 1234567890123456789012345678901234567890
  ==> missing
  fatal: bad object 1234abcdef1234abcdef1234abcdef1234abcdef

Note that the "missing" case is the only one that _doesn't_ give further clarification, and it is likely to be the most common (however just changing "bad object" to "no such object" would be a bad idea, as it makes the second case harder to understand).

-Peff
Previous: Stefan BellerNext: Junio C Hamano
Message 12 of 19 in “corrupt repos does not return error with `git fsck`”
  1. Faheem MithaMay 20, 2015
  2. Matthieu MoyMay 20, 2015
  3. Johannes SchindelinMay 20, 2015
  4. Stefan BellerMay 20, 2015
  5. John KeepingMay 20, 2015
  6. Jeff KingMay 20, 2015
  7. Jeff KingMay 20, 2015
  8. Junio C HamanoMay 20, 2015
  9. Stefan BellerMay 20, 2015
  10. Junio C HamanoMay 20, 2015
  11. Stefan BellerMay 20, 2015
  12. Jeff KingMay 20, 2015
  13. Junio C HamanoMay 20, 2015
  14. Faheem MithaMay 20, 2015
  15. Stefan BellerMay 20, 2015
  16. Faheem MithaMay 20, 2015
  17. Matthieu MoyMay 20, 2015
  18. Faheem MithaMay 20, 2015
  19. Matthieu MoyMay 21, 2015

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.