Skip to content

Commit 0916804

Browse files
committed
Merge branch 'tb/midx-race-in-pack-objects'
The multi-pack-index code did not protect the packfile it is going to depend on from getting removed while in use, which has been corrected. * tb/midx-race-in-pack-objects: builtin/pack-objects.c: ensure pack validity from MIDX bitmap objects builtin/pack-objects.c: ensure included `--stdin-packs` exist builtin/pack-objects.c: avoid redundant NULL check pack-bitmap.c: check preferred pack validity when opening MIDX bitmap
2 parents d8c8dcc + 4090511 commit 0916804

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

builtin/pack-objects.c

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,9 @@ static int want_found_object(const struct object_id *oid, int exclude,
13571357
if (incremental)
13581358
return 0;
13591359

1360+
if (!is_pack_valid(p))
1361+
return -1;
1362+
13601363
/*
13611364
* When asked to do --local (do not include an object that appears in a
13621365
* pack we borrow from elsewhere) or --honor-pack-keep (do not include
@@ -1472,6 +1475,9 @@ static int want_object_in_pack(const struct object_id *oid,
14721475
want = want_found_object(oid, exclude, *found_pack);
14731476
if (want != -1)
14741477
return want;
1478+
1479+
*found_pack = NULL;
1480+
*found_offset = 0;
14751481
}
14761482

14771483
for (m = get_multi_pack_index(the_repository); m; m = m->next) {
@@ -3201,10 +3207,8 @@ static int add_object_entry_from_pack(const struct object_id *oid,
32013207
uint32_t pos,
32023208
void *_data)
32033209
{
3204-
struct rev_info *revs = _data;
3205-
struct object_info oi = OBJECT_INFO_INIT;
32063210
off_t ofs;
3207-
enum object_type type;
3211+
enum object_type type = OBJ_NONE;
32083212

32093213
display_progress(progress_state, ++nr_seen);
32103214

@@ -3215,19 +3219,24 @@ static int add_object_entry_from_pack(const struct object_id *oid,
32153219
if (!want_object_in_pack(oid, 0, &p, &ofs))
32163220
return 0;
32173221

3218-
oi.typep = &type;
3219-
if (packed_object_info(the_repository, p, ofs, &oi) < 0)
3220-
die(_("could not get type of object %s in pack %s"),
3221-
oid_to_hex(oid), p->pack_name);
3222-
else if (type == OBJ_COMMIT) {
3223-
/*
3224-
* commits in included packs are used as starting points for the
3225-
* subsequent revision walk
3226-
*/
3227-
add_pending_oid(revs, NULL, oid, 0);
3228-
}
3222+
if (p) {
3223+
struct rev_info *revs = _data;
3224+
struct object_info oi = OBJECT_INFO_INIT;
3225+
3226+
oi.typep = &type;
3227+
if (packed_object_info(the_repository, p, ofs, &oi) < 0) {
3228+
die(_("could not get type of object %s in pack %s"),
3229+
oid_to_hex(oid), p->pack_name);
3230+
} else if (type == OBJ_COMMIT) {
3231+
/*
3232+
* commits in included packs are used as starting points for the
3233+
* subsequent revision walk
3234+
*/
3235+
add_pending_oid(revs, NULL, oid, 0);
3236+
}
32293237

3230-
stdin_packs_found_nr++;
3238+
stdin_packs_found_nr++;
3239+
}
32313240

32323241
create_object_entry(oid, type, 0, 0, 0, p, ofs);
32333242

@@ -3346,6 +3355,8 @@ static void read_packs_list_from_stdin(void)
33463355
struct packed_git *p = item->util;
33473356
if (!p)
33483357
die(_("could not find pack '%s'"), item->string);
3358+
if (!is_pack_valid(p))
3359+
die(_("packfile %s cannot be accessed"), p->pack_name);
33493360
}
33503361

33513362
/*
@@ -3369,8 +3380,6 @@ static void read_packs_list_from_stdin(void)
33693380

33703381
for_each_string_list_item(item, &include_packs) {
33713382
struct packed_git *p = item->util;
3372-
if (!p)
3373-
die(_("could not find pack '%s'"), item->string);
33743383
for_each_object_in_pack(p,
33753384
add_object_entry_from_pack,
33763385
&revs,

pack-bitmap.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
315315
struct stat st;
316316
char *idx_name = midx_bitmap_filename(midx);
317317
int fd = git_open(idx_name);
318+
uint32_t i;
319+
struct packed_git *preferred;
318320

319321
free(idx_name);
320322

@@ -353,6 +355,20 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
353355
warning(_("multi-pack bitmap is missing required reverse index"));
354356
goto cleanup;
355357
}
358+
359+
for (i = 0; i < bitmap_git->midx->num_packs; i++) {
360+
if (prepare_midx_pack(the_repository, bitmap_git->midx, i))
361+
die(_("could not open pack %s"),
362+
bitmap_git->midx->pack_names[i]);
363+
}
364+
365+
preferred = bitmap_git->midx->packs[midx_preferred_pack(bitmap_git)];
366+
if (!is_pack_valid(preferred)) {
367+
warning(_("preferred pack (%s) is invalid"),
368+
preferred->pack_name);
369+
goto cleanup;
370+
}
371+
356372
return 0;
357373

358374
cleanup:
@@ -429,8 +445,6 @@ static int load_reverse_index(struct bitmap_index *bitmap_git)
429445
* since we will need to make use of them in pack-objects.
430446
*/
431447
for (i = 0; i < bitmap_git->midx->num_packs; i++) {
432-
if (prepare_midx_pack(the_repository, bitmap_git->midx, i))
433-
die(_("load_reverse_index: could not open pack"));
434448
ret = load_pack_revindex(bitmap_git->midx->packs[i]);
435449
if (ret)
436450
return ret;

0 commit comments

Comments
 (0)