make find_pack_revindex() aware of the nasty world
It currently calls die() whenever given offset is not found thinking that such thing should never happen. But this offset may come from a corrupted pack whych _could_ happen and not be found. Callers should deal with this possibility gracefully instead. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
03d660150c
commit
08698b1e32
@ -1053,6 +1053,8 @@ static void check_object(struct object_entry *entry)
|
|||||||
if (reuse_delta && !entry->preferred_base) {
|
if (reuse_delta && !entry->preferred_base) {
|
||||||
struct revindex_entry *revidx;
|
struct revindex_entry *revidx;
|
||||||
revidx = find_pack_revindex(p, ofs);
|
revidx = find_pack_revindex(p, ofs);
|
||||||
|
if (!revidx)
|
||||||
|
goto give_up;
|
||||||
base_ref = nth_packed_object_sha1(p, revidx->nr);
|
base_ref = nth_packed_object_sha1(p, revidx->nr);
|
||||||
}
|
}
|
||||||
entry->in_pack_header_size = used + used_0;
|
entry->in_pack_header_size = used + used_0;
|
||||||
|
@ -140,7 +140,8 @@ struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
|
|||||||
else
|
else
|
||||||
lo = mi + 1;
|
lo = mi + 1;
|
||||||
} while (lo < hi);
|
} while (lo < hi);
|
||||||
die("internal error: pack revindex corrupt");
|
error("bad offset for revindex");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void discard_revindex(void)
|
void discard_revindex(void)
|
||||||
|
18
sha1_file.c
18
sha1_file.c
@ -1388,9 +1388,12 @@ static int packed_delta_info(struct packed_git *p,
|
|||||||
return OBJ_BAD;
|
return OBJ_BAD;
|
||||||
type = packed_object_info(p, base_offset, NULL);
|
type = packed_object_info(p, base_offset, NULL);
|
||||||
if (type <= OBJ_NONE) {
|
if (type <= OBJ_NONE) {
|
||||||
struct revindex_entry *revidx = find_pack_revindex(p, base_offset);
|
struct revindex_entry *revidx;
|
||||||
const unsigned char *base_sha1 =
|
const unsigned char *base_sha1;
|
||||||
nth_packed_object_sha1(p, revidx->nr);
|
revidx = find_pack_revindex(p, base_offset);
|
||||||
|
if (!revidx)
|
||||||
|
return OBJ_BAD;
|
||||||
|
base_sha1 = nth_packed_object_sha1(p, revidx->nr);
|
||||||
mark_bad_packed_object(p, base_sha1);
|
mark_bad_packed_object(p, base_sha1);
|
||||||
type = sha1_object_info(base_sha1, NULL);
|
type = sha1_object_info(base_sha1, NULL);
|
||||||
if (type <= OBJ_NONE)
|
if (type <= OBJ_NONE)
|
||||||
@ -1682,9 +1685,12 @@ static void *unpack_delta_entry(struct packed_git *p,
|
|||||||
* This is costly but should happen only in the presence
|
* This is costly but should happen only in the presence
|
||||||
* of a corrupted pack, and is better than failing outright.
|
* of a corrupted pack, and is better than failing outright.
|
||||||
*/
|
*/
|
||||||
struct revindex_entry *revidx = find_pack_revindex(p, base_offset);
|
struct revindex_entry *revidx;
|
||||||
const unsigned char *base_sha1 =
|
const unsigned char *base_sha1;
|
||||||
nth_packed_object_sha1(p, revidx->nr);
|
revidx = find_pack_revindex(p, base_offset);
|
||||||
|
if (!revidx)
|
||||||
|
return NULL;
|
||||||
|
base_sha1 = nth_packed_object_sha1(p, revidx->nr);
|
||||||
error("failed to read delta base object %s"
|
error("failed to read delta base object %s"
|
||||||
" at offset %"PRIuMAX" from %s",
|
" at offset %"PRIuMAX" from %s",
|
||||||
sha1_to_hex(base_sha1), (uintmax_t)base_offset,
|
sha1_to_hex(base_sha1), (uintmax_t)base_offset,
|
||||||
|
Loading…
Reference in New Issue
Block a user