Skip to content

Commit 5095f44

Browse files
committed
change!: adjust error return types to handle collision detection
This does mean a lot of churn across the tree, but the change is usually just an adjustment to variants of an existing error type, so I expect that most downstream users will require little to no adaption for this change.
1 parent 4f2b649 commit 5095f44

File tree

10 files changed

+30
-10
lines changed

10 files changed

+30
-10
lines changed

gix-commitgraph/src/file/verify.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub mod checksum {
4545
#[derive(thiserror::Error, Debug)]
4646
#[allow(missing_docs)]
4747
pub enum Error {
48+
#[error("failed to hash commit graph file")]
49+
Hasher(#[from] gix_hash::hasher::Error),
4850
#[error(transparent)]
4951
Verify(#[from] gix_hash::verify::Error),
5052
}

gix-filter/src/ident.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub mod apply {
4848
pub enum Error {
4949
#[error("Could not allocate buffer")]
5050
OutOfMemory(#[from] std::collections::TryReserveError),
51+
#[error("Could not hash blob")]
52+
Hasher(#[from] gix_hash::hasher::Error),
5153
}
5254
}
5355

gix-hash/src/hasher/io.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{hasher, Hasher};
66
pub enum Error {
77
#[error(transparent)]
88
Io(#[from] std::io::Error),
9+
#[error("Failed to hash data")]
10+
Hasher(#[from] hasher::Error),
911
}
1012

1113
/// Compute the hash of `kind` for the bytes in the file at `path`, hashing only the first `num_bytes_from_start`

gix-index/src/decode/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ mod error {
1616
pub enum Error {
1717
#[error(transparent)]
1818
Header(#[from] decode::header::Error),
19+
#[error("Could not hash index data")]
20+
Hasher(#[from] gix_hash::hasher::Error),
1921
#[error("Could not parse entry at index {index}")]
2022
Entry { index: u32 },
2123
#[error("Mandatory extension wasn't implemented or malformed.")]
@@ -64,7 +66,7 @@ impl State {
6466
) -> Result<(Self, Option<gix_hash::ObjectId>), Error> {
6567
let _span = gix_features::trace::detail!("gix_index::State::from_bytes()", options = ?_options);
6668
let (version, num_entries, post_header_data) = header::decode(data, object_hash)?;
67-
let start_of_extensions = extension::end_of_index_entry::decode(data, object_hash);
69+
let start_of_extensions = extension::end_of_index_entry::decode(data, object_hash)?;
6870

6971
let mut num_threads = gix_features::parallel::num_threads(thread_limit);
7072
let path_backing_buffer_size = entries::estimate_path_storage_requirements_in_bytes(

gix-index/src/extension/end_of_index_entry/decode.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ use crate::{
1313
/// stored prior to this one to assure they are correct.
1414
///
1515
/// If the checksum wasn't matched, we will ignore this extension entirely.
16-
pub fn decode(data: &[u8], object_hash: gix_hash::Kind) -> Option<usize> {
16+
pub fn decode(data: &[u8], object_hash: gix_hash::Kind) -> Result<Option<usize>, gix_hash::hasher::Error> {
1717
let hash_len = object_hash.len_in_bytes();
1818
if data.len() < MIN_SIZE_WITH_HEADER + hash_len {
19-
return None;
19+
return Ok(None);
2020
}
2121

2222
let start_of_eoie = data.len() - MIN_SIZE_WITH_HEADER - hash_len;
2323
let ext_data = &data[start_of_eoie..data.len() - hash_len];
2424

2525
let (signature, ext_size, ext_data) = extension::decode::header(ext_data);
2626
if signature != SIGNATURE || ext_size as usize != MIN_SIZE {
27-
return None;
27+
return Ok(None);
2828
}
2929

3030
let (offset, checksum) = ext_data.split_at(4);
3131
let offset = from_be_u32(offset) as usize;
3232
let Ok(checksum) = gix_hash::oid::try_from_bytes(checksum) else {
33-
return None;
33+
return Ok(None);
3434
};
3535
if offset < header::SIZE || offset > start_of_eoie || checksum.kind() != gix_hash::Kind::Sha1 {
36-
return None;
36+
return Ok(None);
3737
}
3838

3939
let mut hasher = gix_hash::hasher(gix_hash::Kind::Sha1);
@@ -45,12 +45,12 @@ pub fn decode(data: &[u8], object_hash: gix_hash::Kind) -> Option<usize> {
4545
}
4646

4747
if hasher.finalize().verify(checksum).is_err() {
48-
return None;
48+
return Ok(None);
4949
}
5050
// The last-to-this chunk ends where ours starts
5151
if last_chunk.map_or(true, |s| s.as_ptr_range().end != (&data[start_of_eoie]) as *const _) {
52-
return None;
52+
return Ok(None);
5353
}
5454

55-
Some(offset)
55+
Ok(Some(offset))
5656
}

gix-index/src/extension/end_of_index_entry/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn write_to(
1111
hash_kind: gix_hash::Kind,
1212
offset_to_extensions: u32,
1313
prior_extensions: impl IntoIterator<Item = (Signature, u32)>,
14-
) -> Result<(), std::io::Error> {
14+
) -> Result<(), gix_hash::hasher::io::Error> {
1515
out.write_all(&SIGNATURE)?;
1616
let extension_size: u32 = 4 + hash_kind.len_in_bytes() as u32;
1717
out.write_all(&extension_size.to_be_bytes())?;

gix-index/src/file/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl File {
8686
)
8787
.map_err(|err| match err {
8888
hasher::io::Error::Io(err) => Error::Io(err),
89+
hasher::io::Error::Hasher(err) => Error::Decode(err.into()),
8990
})?
9091
.verify(&expected)
9192
.map_err(decode::Error::from)?;

gix-object/src/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ pub mod verify {
5555
#[derive(Debug, thiserror::Error)]
5656
#[allow(missing_docs)]
5757
pub enum Error {
58+
#[error("Failed to hash object")]
59+
Hasher(#[from] gix_hash::hasher::Error),
5860
#[error(transparent)]
5961
Verify(#[from] gix_hash::verify::Error),
6062
}

gix-odb/src/store_impls/loose/verify.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ pub mod integrity {
1919
kind: gix_object::Kind,
2020
id: gix_hash::ObjectId,
2121
},
22+
#[error("{kind} object {expected} could not be hashed")]
23+
ObjectHasher {
24+
#[source]
25+
source: gix_hash::hasher::Error,
26+
kind: gix_object::Kind,
27+
expected: gix_hash::ObjectId,
28+
},
2229
#[error("{kind} object wasn't re-encoded without change")]
2330
ObjectEncodeMismatch {
2431
#[source]

gix-pack/src/verify.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub mod checksum {
1111
pub enum Error {
1212
#[error("Interrupted by user")]
1313
Interrupted,
14+
#[error("Failed to hash data")]
15+
Hasher(#[from] gix_hash::hasher::Error),
1416
#[error(transparent)]
1517
Verify(#[from] gix_hash::verify::Error),
1618
}

0 commit comments

Comments
 (0)