Skip to content

Commit 8817c24

Browse files
committed
fix: don't crash when object validation failed during verification.
When objects can't be serialized, they will trigger an error that manifests as IO error. Previously we didn't think of the possibility that writing to an im-memory buffer could fail would indeed panic during verification. This is now fixed.
1 parent 891a061 commit 8817c24

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

gitoxide-core/src/corpus/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 0..=3;
1+
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 0..=5;
22

33
pub struct Engine {
44
con: rusqlite::Connection,

gix-pack/src/index/verify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub mod integrity {
1515
#[derive(thiserror::Error, Debug)]
1616
#[allow(missing_docs)]
1717
pub enum Error {
18+
#[error("Reserialization of an object failed")]
19+
Io(#[from] std::io::Error),
1820
#[error("The fan at index {index} is out of order as it's larger then the following value.")]
1921
Fan { index: usize },
2022
#[error("{kind} object {id} could not be decoded")]
@@ -252,9 +254,7 @@ impl index::File {
252254
})?;
253255
if let Mode::HashCrc32DecodeEncode = verify_mode {
254256
encode_buf.clear();
255-
object
256-
.write_to(&mut *encode_buf)
257-
.expect("writing to a memory buffer never fails");
257+
object.write_to(&mut *encode_buf)?;
258258
if encode_buf.as_slice() != buf {
259259
let mut should_return_error = true;
260260
if let Tree = object_kind {

0 commit comments

Comments
 (0)