m4b / goblin

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

panicked at 'attempt to subtract with overflow' #283

Closed charlesxsh closed 3 years ago

charlesxsh commented 3 years ago

for a given input: in.zip

with following code:

fn main(){
    let filepath = "<input file>";
    let data = std::fs::read(filepath).unwrap();
    let _ = goblin::Object::parse(&data);   
}

output:

thread 'main' panicked at 'attempt to subtract with overflow', /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/utils.rs:35:25
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: goblin::pe::utils::section_read_size
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/utils.rs:35:25
   4: goblin::pe::utils::is_in_section
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/utils.rs:58:23
   5: goblin::pe::utils::find_offset
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/utils.rs:77:16
   6: goblin::pe::debug::ImageDebugDirectory::parse_with_opts
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/debug.rs:103:22
   7: goblin::pe::debug::DebugData::parse_with_opts
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/debug.rs:39:13
   8: goblin::pe::PE::parse_with_opts
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/mod.rs:156:35
   9: goblin::pe::PE::parse
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/pe/mod.rs:66:9
  10: goblin::Object::parse
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/goblin-0.4.3/src/lib.rs:316:47
...

expect: properly return error instead of panic

m4b commented 3 years ago

@charlesxsh I believe @skdltmxn 's PR fixes your issue now; could you test it out? I will probably wait a bit to roll up other changes for a minor release, unless this is urgent for some reason.