Skip to content

Commit b7566f0

Browse files
committed
pack-bitmap: handle missing bitmap for base MIDX
open_midx_bitmap_1() calls prepare_midx_bitmap_git() to load the bitmap for a chained MIDX's base layer. If the base MIDX does not have an associated bitmap file (e.g., it was not generated, or was deleted by gc), prepare_midx_bitmap_git() returns NULL. The return value is stored in bitmap_git->base and immediately dereferenced on the next line to read base->base_nr, causing a NULL pointer crash. This can happen in practice with incremental MIDX chains: the base MIDX may have been written without --write-bitmap-index, or the bitmap may have been pruned while the incremental layer's bitmap still references it. Check the return value and go to the cleanup label (which unmaps the current bitmap and returns -1) so the caller falls back to non-bitmap object enumeration, matching the handling of other bitmap loading failures in the same function (lines 502, 507, 511, 517). Pointed out by Coverity. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 6d4740c commit b7566f0

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

pack-bitmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
523523

524524
if (midx->base_midx) {
525525
bitmap_git->base = prepare_midx_bitmap_git(midx->base_midx);
526+
if (!bitmap_git->base) {
527+
warning(_("could not open bitmap for base MIDX"));
528+
goto cleanup;
529+
}
526530
bitmap_git->base_nr = bitmap_git->base->base_nr + 1;
527531
} else {
528532
bitmap_git->base_nr = 0;

0 commit comments

Comments
 (0)