]> git.ipfire.org Git - thirdparty/git.git/commit
t5326: demonstrate potential bitmap corruption
authorTaylor Blau <me@ttaylorr.com>
Mon, 22 Aug 2022 19:50:32 +0000 (15:50 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Aug 2022 20:04:21 +0000 (13:04 -0700)
commit65168c42df25c61cfbe3ab481549b250c150f1f6
treef8574da16d6ece239fbb06ff42e5fbcb5316bc9a
parentad60dddad72dfb8367bd695028b5b8dc6c33661b
t5326: demonstrate potential bitmap corruption

It is possible to generate a corrupt MIDX bitmap when certain conditions
are met. This happens when the preferred pack "P" changes to one (say,
"Q") that:

  - "Q" has objects included in an existing MIDX,
  - but "Q" is different than "P",
  - and "Q" and "P" have some objects in common

When this is the case, not all objects from "Q" will be selected from
"Q" (ie., the generated MIDX will represent them as coming from a
different pack), despite "Q" being preferred.

This is an invariant violation, since all objects contained in the
MIDX's preferred pack are supposed to originate from the preferred pack.
In other words, all duplicate objects are resolved in favor of the copy
that comes from the MIDX's preferred pack, if any.

This violation results in a corrupt object order, which cannot be
interpreted by the pack-bitmap code, leading to broken clones and other
defects.

This test demonstrates the above problem by constructing a minimal
reproduction, and showing that the final `git clone` invocation fails.

The reproduction is mostly straightforward, except that the new pack
generated between MIDX writes (which is necessary in order to prevent
that operation from being a noop) must sort ahead of all existing packs
in order to prevent a different pack (neither "P" nor "Q") from
appearing as preferred (meaning all its objects appear in order at the
beginning of the pseudo-pack order).

Subsequent commits will first refactor the midx.c::get_sorted_entries()
function, and then fix this bug.

Reported-by: Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5326-multi-pack-bitmaps.sh