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

[PATCH 06/10] pack-check: convert "internal error" die to a BUG()

From
Jeff King <peff@peff.net>
Date
Feb 24, 2020, 04:33 UTC
Message-ID
<20200224043318.GF1018190@coredump.intra.peff.net>
In-Reply-To
<20200224042625.GA1015553@coredump.intra.peff.net>

If we fail to load the oid from the index of a packfile, we'll die() with an "internal error". But this should never happen: we'd fail here only if the idx needed to be lazily opened (but we've already opened it) or if we asked for an out-of-range index (but we're iterating using the same count that we'd check the range against). A corrupted index might have a bogus count (e.g., too large for its size), but we'd have complained and aborted already when opening the index initially.

While we're here, we can add a few details so that if this bug ever _does_ trigger, we'll have a bit more information.

Signed-off-by: Jeff King <peff@peff.net>
---
Most code in this situation doesn't even bother checking the return
value. So I would also be tempted to simply drop the conditional
entirely as unreachable.
 pack-check.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/pack-check.c b/pack-check.c
index e4ef71c673..39196ecfbc 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -99,7 +99,8 @@ static int verify_packfile(struct repository *r,
 	for (i = 0; i < nr_objects; i++) {
 		entries[i].oid.hash = nth_packed_object_sha1(p, i);
 		if (!entries[i].oid.hash)
-			die("internal error pack-check nth-packed-object");
+			BUG("unable to get oid of object %lu from %s",
+			    (unsigned long)i, p->pack_name);
 		entries[i].offset = nth_packed_object_offset(p, i);
 		entries[i].nr = i;
 	}
-- 
2.25.1.823.g95c5488cf7
Previous: Jeff KingNext: Jeff King
Message 9 of 14 in “removing nth_packed_object_sha1()”
  1. 0/10 removing nth_packed_object_sha1()Jeff King, Feb 24, 2020
  2. 01/10 nth_packed_object_oid(): use customary integer returnJeff King, Feb 24, 2020
  3. Jeff KingFeb 24, 2020
  4. 02/10 pack-objects: read delta base oid into object_id structJeff King, Feb 24, 2020
  5. brian m. carlsonFeb 25, 2020
  6. 03/10 pack-objects: convert oe_set_delta_ext() to use object_idJeff King, Feb 24, 2020
  7. 04/10 pack-objects: use object_id struct in pack-reuse codeJeff King, Feb 24, 2020
  8. 05/10 pack-bitmap: use object_id when loading on-disk bitmapsJeff King, Feb 24, 2020
  9. 06/10 pack-check: convert "internal error" die to a BUG()Jeff King, Feb 24, 2020
  10. 07/10 pack-check: push oid lookup into loopJeff King, Feb 24, 2020
  11. 08/10 packed_object_info(): use object_id for returning delta baseJeff King, Feb 24, 2020
  12. 09/10 packed_object_info(): use object_id internally for delta baseJeff King, Feb 24, 2020
  13. 10/10 packfile: drop nth_packed_object_sha1()Jeff King, Feb 24, 2020
  14. brian m. carlsonFeb 25, 2020

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.