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

[PATCH 6/6] fsck: check HAS_OBJ more consistently

From
Jeff King <peff@peff.net>
Date
Jan 16, 2017, 21:34 UTC
Message-ID
<20170116213457.n7twsvr2vozdpgcj@sigill.intra.peff.net>
In-Reply-To
<20170116212231.ojoqzlajpszifaf3@sigill.intra.peff.net>

There are two spots that call lookup_object() and assume that a non-NULL result means we have the object:

  1. When we're checking the objects given to us by the user
     on the command line.
  2. When we're checking if a reflog entry is valid.

This generally follows fsck's mental model that we will have looked at and loaded a "struct object" for each object in the repository. But it misses one case: if another object _mentioned_ an object, but we didn't actually parse it or verify that it exists, it will still have a struct.

It's not clear if this is a triggerable bug or not. Certainly the later parts of the reachability check need to be careful of this, and do so by checking the HAS_OBJ flag. But both of these steps happen before we start traversing, so probably we won't have followed any links yet. Still, it's easy enough to be defensive here.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/fsck.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 8ae065b2d..28d3cbb14 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -398,7 +398,7 @@ static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,
 
 	if (!is_null_sha1(sha1)) {
 		obj = lookup_object(sha1);
-		if (obj) {
+		if (obj && (obj->flags & HAS_OBJ)) {
 			if (timestamp && name_objects)
 				add_decoration(fsck_walk_options.object_names,
 					obj,
@@ -755,7 +755,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		if (!get_sha1(arg, sha1)) {
 			struct object *obj = lookup_object(sha1);
 
-			if (!obj) {
+			if (!obj || !(obj->flags & HAS_OBJ)) {
 				error("%s: object missing", sha1_to_hex(sha1));
 				errors_found |= ERROR_OBJECT;
 				continue;
-- 
2.11.0.642.gd6f8cda6c
Previous: Jeff KingNext: Jeff King
Message 8 of 15 in “fsck --connectivity-check misses some corruption”
  1. 0/6 fsck --connectivity-check misses some corruptionJeff King, Jan 16, 2017
  2. 1/6 t1450: clean up sub-objects in duplicate-entry testJeff King, Jan 16, 2017
  3. Junio C HamanoJan 17, 2017
  4. Jeff KingJan 17, 2017
  5. 2/6 fsck: report trees as danglingJeff King, Jan 16, 2017
  6. Junio C HamanoJan 17, 2017
  7. 5/6 fsck: do not fallback "git fsck <bogus>" to "git fsck"Jeff King, Jan 16, 2017
  8. 6/6 fsck: check HAS_OBJ more consistentlyJeff King, Jan 16, 2017
  9. 3/6 fsck: prepare dummy objects for --connectivity-checkJeff King, Jan 16, 2017
  10. Junio C HamanoJan 17, 2017
  11. Junio C HamanoJan 17, 2017
  12. Jeff KingJan 17, 2017
  13. 4/6 fsck: tighten error-checks of "git fsck <head>"Jeff King, Jan 16, 2017
  14. Junio C HamanoJan 17, 2017
  15. Jeff KingJan 16, 2017

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.