m4b / goblin

An impish, cross-platform binary parsing crate, written in Rust
MIT License
1.2k stars 160 forks source link

MultiArch parsing non fat binary panicked with Scroll(BadOffset()) #250

Closed messense closed 3 years ago

messense commented 3 years ago

Ideally it should return an Err instead of panicking?

[dependencies]
goblin = "0.3.1"
use goblin::mach::MultiArch;

fn main() {
    let fat = MultiArch::new(include_bytes!("thin_x86_64")).unwrap();   //  this returns Ok
    println!("{:?}", fat);  // panicked here
}

thin_x86_64 file thin_x86_64.zip

$ cargo run
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Scroll(BadOffset(8))', goblin-0.3.1/src/mach/mod.rs:413:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
MultiArch

https://github.com/m4b/goblin/blob/8d91dd76a1950882301481d92f053e8649faaae7/src/mach/mod.rs#L413

messense commented 3 years ago

OK, I think I should use Mach::parse instead of MultiArch::parse.

m4b commented 3 years ago

Ok but this is still really undesirable behavior panicking in the debug printer. Would be nice to change that unwrap to an unwra_or(“NO_ARCHES”) or something