Skip to content

Commit

Permalink
fix: Panic when reading a file truncated in the middle of an XZ block…
Browse files Browse the repository at this point in the history
… header
  • Loading branch information
Pr0methean committed Jul 15, 2024
1 parent 1e7085f commit 8656826
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/read/xz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ impl<R: Read> Read for XzDecoder<R> {
}
digest.update(&b);
}
let mut b = vec![0u8; header_end - *reader.count];
let Some(padding_bytes) = header_end.checked_sub(*reader.count) else {
return error("Invalid XZ block header (too short)");
};
let mut b = vec![0u8; padding_bytes];
reader.read_exact(b.as_mut_slice())?;
if !b.iter().all(|&b| b == 0) {
return error("Invalid XZ block header padding");
Expand Down

0 comments on commit 8656826

Please sign in to comment.