Skip to content

Commit fc150ca

Browse files
ttaylorrgitster
authored andcommitted
packed_object_info(): convert to new revindex API
Convert another call of 'find_pack_revindex()' to its replacement 'pack_pos_to_offset()'. Likewise: - Avoid manipulating `struct packed_git`'s `revindex` pointer directly by removing the pointer-as-array indexing. - Add an additional guard to check that the offset 'obj_offset()' points to a real object. This should be the case with well-behaved callers to 'packed_object_info()', but isn't guarenteed. Other blocks that fill in various other values from the 'struct object_info' request handle bad inputs by setting the type to 'OBJ_BAD' and jumping to 'out'. Do the same when given a bad offset here. The previous code would have segfaulted when given a bad 'obj_offset' value, since 'find_pack_revindex()' would return 'NULL', and then the line that fills 'oi->disk_sizep' would try to access 'NULL[1]' with a stride of 16 bytes (the width of 'struct revindex_entry)'. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a3f54d commit fc150ca

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packfile.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,15 @@ int packed_object_info(struct repository *r, struct packed_git *p,
15371537
}
15381538

15391539
if (oi->disk_sizep) {
1540-
struct revindex_entry *revidx = find_pack_revindex(p, obj_offset);
1541-
*oi->disk_sizep = revidx[1].offset - obj_offset;
1540+
uint32_t pos;
1541+
if (offset_to_pack_pos(p, obj_offset, &pos) < 0) {
1542+
error("could not find object at offset %"PRIuMAX" "
1543+
"in pack %s", (uintmax_t)obj_offset, p->pack_name);
1544+
type = OBJ_BAD;
1545+
goto out;
1546+
}
1547+
1548+
*oi->disk_sizep = pack_pos_to_offset(p, pos + 1) - obj_offset;
15421549
}
15431550

15441551
if (oi->typep || oi->type_name) {

0 commit comments

Comments
 (0)