wcampbell0x2a / backhand

Library and binaries for the reading, creating, and modification of SquashFS file systems
Apache License 2.0
117 stars 10 forks source link

Fails to read SquashFS created with mksquashfs #282

Closed eatradish closed 1 year ago

eatradish commented 1 year ago

My code:

use std::io::BufReader;

use backhand::FilesystemReader;

fn main() {
    let archive = BufReader::new(
        std::fs::File::open(
            "/home/saki/mirror/aosc-os/os-amd64/desktop/aosc-os_desktop_20230705_amd64.squashfs",
        )
        .unwrap(),
    );
    let reader = FilesystemReader::from_reader(archive).unwrap();
    let mut size = 0;

    for node in reader.files() {
        match &node.inner {
            backhand::InnerNode::File(f) => size += f.basic.file_size,
            _ => continue,
        }
    }

    dbg!(size);
}

Squashfs file: https://releases.aosc.io/os-amd64/desktop/aosc-os_desktop_20230705_amd64.squashfs

Output:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CorruptedOrInvalidSquashfs', src/main.rs:12:57
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
   1: core::panicking::panic_fmt
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
   2: core::result::unwrap_failed
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/result.rs:1651:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/result.rs:1076:23
   4: backhand_test::main
             at ./src/main.rs:12:18
   5: core::ops::function::FnOnce::call_once
             at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This file (aosc-os_desktop_20230705_amd64.squashfs) was compressed with mksquashfs 4.5 with the following arguments:

    let output = Command::new("mksquashfs")
        .arg(root)
        .arg(target)
        .arg("-comp")
        .arg("xz")
        .arg("-processors")
        .arg(format!("{}", threads))
        .spawn()?
        .wait_with_output()?;

At https://github.com/AOSC-Dev/aoscbootstrap/blob/646aef373fcbeafb8a0f1cf487e952ae34060ed3/src/fs.rs#L74

wcampbell0x2a commented 1 year ago

I pushed https://github.com/wcampbell0x2a/backhand/pull/283 which should fix this problem. Thanks!

eatradish commented 1 year ago

I used backhand = { git = "https://github.com/wcampbell0x2a/backhand", rev = "3363bd836accb9d9b8a1bac837de9c0d2d862e35"} The issue seems to remain the same

wcampbell0x2a commented 1 year ago

I definitely see the following when I run your snip of code:

./target/release/backhand-282
[src/[main.rs:22](http://main.rs:22/)] size = 1745037190
wcampbell0x2a commented 1 year ago

Merged https://github.com/wcampbell0x2a/backhand/pull/283, lmk if this is still an issue.