Skip to content

Commit

Permalink
refactor checking whether logN is too large
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jan 14, 2025
1 parent 9c37abd commit 2b5707f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions libbz2-rs-sys/src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,13 +1112,15 @@ pub(crate) fn decompress(
}
}
if current_block == Block46 {
if (1 << logN) >= 2 * 1024 * 1024 {
// Check that N doesn't get too big, so that es doesn't
// go negative. The maximum value that can be
// RUNA/RUNB encoded is equal to the block size (post
// the initial RLE), viz, 900k, so bounding N at 2
// million should guard against overflow without
// rejecting any legitimate inputs.
// Check that N doesn't get too big, so that es doesn't
// go negative. The maximum value that can be
// RUNA/RUNB encoded is equal to the block size (post
// the initial RLE), viz, 900k, so bounding N at 2
// million should guard against overflow without
// rejecting any legitimate inputs.
const LOG_2MB: u8 = 21; // 2 * 1024 * 1024

if logN >= LOG_2MB {
error!(BZ_DATA_ERROR);
} else {
let mul = match nextSym as u16 {
Expand Down

0 comments on commit 2b5707f

Please sign in to comment.