Skip to content

Commit

Permalink
Merge pull request #806 from ReFirmLabs/squashfs_v2_be_bugfix
Browse files Browse the repository at this point in the history
Fixed SquashFSv2 bug, added SquashFSv2 test
  • Loading branch information
devttys0 authored Dec 24, 2024
2 parents dda0001 + 9927db2 commit a7c0fe3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/structures/squashfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn parse_squashfs_header(sqsh_data: &[u8]) -> Result<SquashFSHeader, Structu
// Sanity check the version number
if squashfs_version <= MAX_SQUASHFS_VERSION && squashfs_version > 0 {
let squashfs_header_size: usize;
let squashfs_header: HashMap<String, usize>;
let mut squashfs_header: HashMap<String, usize>;

// Parse the SquashFS header, using the appropriate version header.
if squashfs_version == 4 {
Expand All @@ -123,6 +123,24 @@ pub fn parse_squashfs_header(sqsh_data: &[u8]) -> Result<SquashFSHeader, Structu
}
Ok(squash3_header) => {
squashfs_header = squash3_header.clone();

// Adjust the reported header values for v1 and v2 images
if squashfs_version < 3 {
squashfs_header
.insert("uid_start".to_string(), squashfs_header["uid_start_2"]);
squashfs_header
.insert("guid_start".to_string(), squashfs_header["guid_start_2"]);
squashfs_header
.insert("image_size".to_string(), squashfs_header["bytes_used_2"]);
squashfs_header.insert(
"inode_table_start".to_string(),
squashfs_header["inode_table_start_2"],
);
squashfs_header.insert(
"directory_table_start".to_string(),
squashfs_header["directory_table_start_2"],
);
}
}
}
}
Expand Down
Binary file added tests/inputs/squashfs_v2.bin
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/squashfs_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod common;

#[test]
fn integration_test() {
const SIGNATURE_TYPE: &str = "squashfs";
const INPUT_FILE_NAME: &str = "squashfs_v2.bin";
common::integration_test(SIGNATURE_TYPE, INPUT_FILE_NAME);
}

0 comments on commit a7c0fe3

Please sign in to comment.