Skip to content

Commit

Permalink
Merge pull request #230 from crepererum-oss/crepererum/issue228
Browse files Browse the repository at this point in the history
refactor: harden decompression checks
  • Loading branch information
crepererum authored Jul 17, 2024
2 parents d273568 + 929ed46 commit e7b13aa
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ pub(crate) fn decompress_value(v: &[u8]) -> Result<Vec<u8>> {
Ok(out) => {
return Ok(out);
}
Err(lz4_flex::block::DecompressError::OutputTooSmall { expected, .. })
if expected > out_len =>
{
out_len = expected.max(out_len.saturating_mul(2));
Err(lz4_flex::block::DecompressError::OutputTooSmall { expected, actual }) => {
assert_eq!(actual, out_len);
assert!(
expected > actual,
"failed: expected ({expected}) > actual ({actual})"
);
out_len = expected.max(actual.saturating_mul(2));
}
Err(e) => {
return Err(e).context("decompression");
Expand Down

0 comments on commit e7b13aa

Please sign in to comment.