Skip to content

Commit

Permalink
Merge pull request #256 from wcampbell0x2a/cleanup-block-size-check
Browse files Browse the repository at this point in the history
Cleanup block_size check
  • Loading branch information
wcampbell0x2a authored Jun 10, 2023
2 parents 7e533ab + 7d57b3a commit e89c302
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/squashfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,9 @@ impl Squashfs {
),
)?;

let power_of_two = superblock.block_size != 0
&& (superblock.block_size & (superblock.block_size - 1)) == 0;
if (superblock.block_size > MAX_BLOCK_SIZE)
|| (superblock.block_size < MIN_BLOCK_SIZE)
|| !power_of_two
{
let block_size = superblock.block_size;
let power_of_two = block_size != 0 && (block_size & (block_size - 1)) == 0;
if !(MIN_BLOCK_SIZE..=MAX_BLOCK_SIZE).contains(&block_size) || !power_of_two {
error!("block_size({:#02x}) invalid", superblock.block_size);
return Err(BackhandError::CorruptedOrInvalidSquashfs);
}
Expand Down

0 comments on commit e89c302

Please sign in to comment.