Skip to content

Commit 3b7bff2

Browse files
committed
gix-commitgraph: ignore v1 bloom hashes
Signed-off-by: Vicent Marti <vmg@strn.cat>
1 parent a85c1fe commit 3b7bff2

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

gix-commitgraph/src/file/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl File {
148148
bits_per_entry: from_be_u32(&data[data_range.start + 8..][..4]),
149149
};
150150
let bloom_data_payload_len = data_range.len() - BLOOM_FILTER_HEADER_SIZE;
151-
if bloom_index_offsets_are_valid(&data[index_range.clone()], bloom_data_payload_len) {
151+
if settings.is_supported() && bloom_index_offsets_are_valid(&data[index_range.clone()], bloom_data_payload_len) {
152152
bloom_filter_settings = Some(settings);
153153
bloom_filter_data_len = bloom_data_payload_len;
154154
bloom_filter_data_offset = Some(data_range.start + BLOOM_FILTER_HEADER_SIZE);

gix-commitgraph/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ pub struct BloomFilterSettings {
5050
pub bits_per_entry: u32,
5151
}
5252

53+
impl BloomFilterSettings {
54+
pub(crate) fn is_supported(&self) -> bool {
55+
match self.hash_version {
56+
// Git's changed-path Bloom filter v1 hashes are deprecated, so we intentionally
57+
// only support the current v2 format and fall back when older data is encountered.
58+
2 => true,
59+
_ => false,
60+
}
61+
}
62+
}
63+
5364
/// A complete commit graph.
5465
///
5566
/// The data in the commit graph may come from a monolithic `objects/info/commit-graph` file, or it

gix-commitgraph/tests/access/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ fn bloom_is_disabled_if_bidx_offsets_are_invalid() {
227227
);
228228
}
229229

230+
#[test]
231+
fn bloom_is_disabled_if_hash_version_is_unsupported() {
232+
let tmp = scripted_fixture_writable("changed_paths_v2.sh").expect("fixture available");
233+
mutate_commit_graph(tmp.path(), |data| {
234+
let entries = parse_chunk_table(data);
235+
let bdat = find_chunk_index(&entries, *b"BDAT").expect("BDAT present in fixture");
236+
let bdat_offset = entries[bdat].offset as usize;
237+
data[bdat_offset..bdat_offset + 4].copy_from_slice(&1u32.to_be_bytes());
238+
});
239+
let graph = gix_commitgraph::Graph::from_info_dir(&info_dir(tmp.path())).expect("graph remains readable");
240+
assert!(
241+
graph.bloom_filter_settings().is_none(),
242+
"unsupported hash versions disable Bloom so callers fall back safely"
243+
);
244+
}
245+
230246
#[derive(Clone, Copy)]
231247
struct ChunkTableEntry {
232248
id: [u8; 4],
Binary file not shown.

0 commit comments

Comments
 (0)