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

Better error messages for corrupt databases

From
Linus Torvalds <torvalds@osdl.org>
Date
Jan 11, 2007, 22:09 UTC
Message-ID
<Pine.LNX.4.64.0701111400031.3594@woody.osdl.org>
In-Reply-To
<7vodp52qzz.fsf@assigned-by-dhcp.cox.net>

This fixes another problem that Andy's case showed: git-fsck-objects reports nonsensical results for corrupt objects.

There were actually two independent and confusing problems:
 - when we had a zero-sized file and used map_sha1_file, mmap() would 
   return EINVAL, and git-fsck-objects would report that as an insane and 
   confusing error. I don't know when this was introduced, it might have 
   been there forever.
 - when "parse_object()" returned NULL, fsck would say "object not found", 
   which can be very confusing, since obviously the object might "exist", 
   it's just unparseable because it's totally corrupt.

So this just makes "xmmap()" return NULL for a zero-sized object (which is a valid thing pointer, exactly the same way "malloc()" can return NULL for a zero-sized allocation). That fixes the first problem (but we could have fixed it in the caller too - I don't personally much care whichever way it goes, but maybe somebody should check that the NO_MMAP case does something sane in this case too?).

And the second problem is solved by just making the error message slightly clearer - the failure to parse an object may be because it's missing or corrupt, not necessarily because it's not "found".

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

This would hopefully have made the error case Andy had a bit more readable and understandable.

diff --git a/fsck-objects.c b/fsck-objects.c
index 0d8a8eb..81f00db 100644
--- a/fsck-objects.c
+++ b/fsck-objects.c
@@ -290,7 +290,7 @@ static int fsck_sha1(unsigned char *sha1)
 {
 	struct object *obj = parse_object(sha1);
 	if (!obj)
-		return error("%s: object not found", sha1_to_hex(sha1));
+		return error("%s: object corrupt or missing", sha1_to_hex(sha1));
 	if (obj->flags & SEEN)
 		return 0;
 	obj->flags |= SEEN;
diff --git a/git-compat-util.h b/git-compat-util.h
index f8d46d5..8781e8e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -202,6 +202,8 @@ static inline void *xmmap(void *start, size_t length,
 {
 	void *ret = mmap(start, length, prot, flags, fd, offset);
 	if (ret == MAP_FAILED) {
+		if (!length)
+			return NULL;
 		release_pack_memory(length);
 		ret = mmap(start, length, prot, flags, fd, offset);
 		if (ret == MAP_FAILED)
Previous: Junio C HamanoNext: Shawn O. Pearce
Message 12 of 24 in “tree corrupted on disk quota full”
  1. Michael S. TsirkinJan 11, 2007
  2. Andreas EricssonJan 11, 2007
  3. Andy WhitcroftJan 11, 2007
  4. Michael S. TsirkinJan 11, 2007
  5. Andreas EricssonJan 11, 2007
  6. Linus TorvaldsJan 11, 2007
  7. Linus TorvaldsJan 11, 2007
  8. Linus TorvaldsJan 11, 2007
  9. Junio C HamanoJan 11, 2007
  10. Andy WhitcroftJan 11, 2007
  11. Junio C HamanoJan 11, 2007
  12. Better error messages for corrupt databasesLinus Torvalds, Jan 11, 2007
  13. Shawn O. PearceJan 12, 2007
  14. Linus TorvaldsJan 11, 2007
  15. Andy WhitcroftJan 11, 2007
  16. Linus TorvaldsJan 11, 2007
  17. Michael S. TsirkinJan 11, 2007
  18. Linus TorvaldsJan 11, 2007
  19. Michael S. TsirkinJan 11, 2007
  20. Linus TorvaldsJan 11, 2007
  21. Michael S. TsirkinJan 11, 2007
  22. Linus TorvaldsJan 12, 2007
  23. Shawn O. PearceJan 12, 2007
  24. Junio C HamanoJan 13, 2007

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.