Commit 5a17689a92bb716ecff551f2a18eab30e762ed6b

Stefan Sperling 2020-09-24T00:28:58

fix matching the object ID of the first object in a pack index An object ID which appears first in a pack index was wrongly ignored by got_packidx_match_id_str_prefix(). The result was a spurious "object not found" error when this object ID was passed on the command line. Reported by jrick on freenode who was lucky enough to this edge case!

diff --git a/lib/pack.c b/lib/pack.c
index ad61697..71b5e07 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -468,7 +468,7 @@ got_packidx_match_id_str_prefix(struct got_object_id_queue *matched_ids,
 	char hex[3];
 	size_t prefix_len = strlen(id_str_prefix);
 	struct got_packidx_object_id *oid;
-	int i;
+	uint32_t i;
 
 	SIMPLEQ_INIT(matched_ids);
 
@@ -482,9 +482,6 @@ got_packidx_match_id_str_prefix(struct got_object_id_queue *matched_ids,
 		return got_error_path(id_str_prefix, GOT_ERR_BAD_OBJ_ID_STR);
 
 	i = be32toh(packidx->hdr.fanout_table[id0 - 1]);
-	if (i == 0)
-		return NULL;
-
 	oid = &packidx->hdr.sorted_ids[i];
 	while (i < totobj && oid->sha1[0] == id0) {
 		char id_str[SHA1_DIGEST_STRING_LENGTH];