Skip to content

Commit 952fc68

Browse files
ttaylorrgitster
authored andcommitted
write_reuse_object(): convert to new revindex API
First replace 'find_pack_revindex()' with its replacement 'offset_to_pack_pos()'. This prevents any bogus OFS_DELTA that may make its way through until 'write_reuse_object()' from causing a bad memory read (if 'revidx' is 'NULL') Next, replace a direct access of '->nr' with the wrapper function 'pack_pos_to_index()'. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f33fb6e commit 952fc68

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

builtin/pack-objects.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
419419
{
420420
struct packed_git *p = IN_PACK(entry);
421421
struct pack_window *w_curs = NULL;
422-
struct revindex_entry *revidx;
422+
uint32_t pos;
423423
off_t offset;
424424
enum object_type type = oe_type(entry);
425425
off_t datalen;
@@ -436,10 +436,15 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,
436436
type, entry_size);
437437

438438
offset = entry->in_pack_offset;
439-
revidx = find_pack_revindex(p, offset);
440-
datalen = revidx[1].offset - offset;
439+
if (offset_to_pack_pos(p, offset, &pos) < 0)
440+
die(_("write_reuse_object: could not locate %s, expected at "
441+
"offset %"PRIuMAX" in pack %s"),
442+
oid_to_hex(&entry->idx.oid), (uintmax_t)offset,
443+
p->pack_name);
444+
datalen = pack_pos_to_offset(p, pos + 1) - offset;
441445
if (!pack_to_stdout && p->index_version > 1 &&
442-
check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) {
446+
check_pack_crc(p, &w_curs, offset, datalen,
447+
pack_pos_to_index(p, pos))) {
443448
error(_("bad packed object CRC for %s"),
444449
oid_to_hex(&entry->idx.oid));
445450
unuse_pack(&w_curs);

0 commit comments

Comments
 (0)