Showing the changes to git-commitgraph/src (1 of 1 file). Show all
Unified · Split
| @@ -39,6 +39,8 @@ pub enum Error { · 38 unmodified lines | ||
| 39 | 39 | }, |
| 40 | 40 | #[error("Missing required chunk {:?}", .0.as_bstr())] |
| 41 | 41 | MissingChunk(ChunkId), |
| 42 | + #[error("{0}")] | |
| 43 | + Trailer(String), | |
| 42 | 44 | #[error("Commit-graph file uses unsupported hash version: {0}")] |
| 43 | 45 | UnsupportedHashVersion(u8), |
| 44 | 46 | #[error("Unsupported commit-graph file version: {0}")] |
| @@ -47,7 +49,8 @@ pub enum Error { · 2 unmodified lines | ||
| 47 | 49 | |
| 48 | 50 | const CHUNK_LOOKUP_SIZE: usize = 12; |
| 49 | 51 | const HEADER_LEN: usize = 8; |
| 50 | −const MIN_FILE_SIZE: usize = HEADER_LEN + ((MIN_CHUNKS + 1) * CHUNK_LOOKUP_SIZE); | |
| 52 | +const TRAILER_LEN: usize = SHA1_SIZE; | |
| 53 | +const MIN_FILE_SIZE: usize = HEADER_LEN + ((MIN_CHUNKS + 1) * CHUNK_LOOKUP_SIZE) + TRAILER_LEN; | |
| 51 | 54 | const OID_LOOKUP_ENTRY_SIZE: usize = SHA1_SIZE; |
| 52 | 55 | |
| 53 | 56 | // Required chunks: OIDF, OIDL, CDAT |
| @@ -262,6 +265,14 @@ impl TryFrom<&Path> for File { · 208 unmodified lines | ||
| 262 | 265 | ))); |
| 263 | 266 | } |
| 264 | 267 | |
| 268 | + let actual_trailer_len = data_size.saturating_sub(chunk_offset); | |
| 269 | + if actual_trailer_len != TRAILER_LEN { | |
| 270 | + return Err(Error::Trailer(format!( | |
| 271 | + "Expected commit-graph trailer to contain {} bytes, got {}", | |
| 272 | + TRAILER_LEN, actual_trailer_len | |
| 273 | + ))); | |
| 274 | + } | |
| 275 | + | |
| 265 | 276 | let fan_offset = fan_offset.ok_or_else(|| Error::MissingChunk(OID_FAN_CHUNK_ID))?; |
| 266 | 277 | let oid_lookup_offset = oid_lookup_offset.ok_or_else(|| Error::MissingChunk(OID_LOOKUP_CHUNK_ID))?; |
| 267 | 278 | let commit_data_offset = commit_data_offset.ok_or_else(|| Error::MissingChunk(COMMIT_DATA_CHUNK_ID))?; |