Skip to content

Commit

Permalink
Merge c306fd9 into c4ba053
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a authored Nov 19, 2024
2 parents c4ba053 + c306fd9 commit e07554b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 108 deletions.
3 changes: 2 additions & 1 deletion backhand/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ pub trait SquashFsReader: BufReadSeek + Sized {
)?;

let mut inodes = IntMap::default();
inodes.try_reserve(superblock.inode_count as usize)?;
// Be nice the allocator, and only allocate a max of u16::MAX count of Indoes
inodes.try_reserve(superblock.inode_count.min(u16::MAX as u32) as usize)?;

let byte_len = bytes.len();
let mut cursor = Cursor::new(bytes);
Expand Down
7 changes: 5 additions & 2 deletions backhand/src/squashfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ impl<'b> Squashfs<'b> {
for d in &dirs {
trace!("extracting entry: {:#?}", d.dir_entries);
for entry in &d.dir_entries {
let Ok(inode_key) = (d.inode_num as i32 + entry.inode_offset as i32).try_into()
else {
let Ok(inode_key) = (d.inode_num as i32 + entry.inode_offset as i32).try_into() else {
return Err(BackhandError::CorruptedOrInvalidSquashfs);
};
let Some(found_inode) = &self.inodes.get(&inode_key) else {
Expand All @@ -533,6 +532,10 @@ impl<'b> Squashfs<'b> {
// BasicDirectory, ExtendedDirectory
InodeId::BasicDirectory | InodeId::ExtendedDirectory => {
// its a dir, extract all children inodes
if *found_inode == dir_inode {
error!("self referential dir to already read inode");
return Err(BackhandError::UnexpectedInode(dir_inode.inner.clone()));
}
self.extract_dir(fullpath, root, found_inode, &self.id)?;
InnerNode::Dir(SquashfsDir::default())
}
Expand Down
Loading

0 comments on commit e07554b

Please sign in to comment.