Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic called Result::unwrap() on an Err value: TryFromIntError(()) #28

Open
qarmin opened this issue Nov 21, 2024 · 0 comments
Open

Panic called Result::unwrap() on an Err value: TryFromIntError(()) #28

qarmin opened this issue Nov 21, 2024 · 0 comments

Comments

@qarmin
Copy link

qarmin commented Nov 21, 2024

Code

fn check_file(path: &str) {
    let content = match fs::read(&path) {
        Ok(content) => content,
        Err(e) => {
            println!("{e}");
            return;
        }
    };
    println!("Checking file: {path}");

    let mut parser = MediaParser::new();

    // Parse unseekable
    let reader = Cursor::new(&content);
    let Ok(ms) = MediaSource::unseekable(reader) else {
        return ;
    };
    let iter: Result<ExifIter, _> = parser.parse(ms);
    if let Ok(iter) = iter {
        let _ = iter.parse_gps_info();
        for i in iter {
            let s = i;
            s.tag_code();
            s.get_value();
            let _ = s.get_result();
            s.tag();
            s.ifd_index();
            s.has_value();
        }
    }

    let reader = Cursor::new(&content);
    let Ok(ms) = MediaSource::unseekable(reader) else {
        return ;
    };
    let _: Result<TrackInfo, _> = parser.parse(ms);

    // Parse seekable
    let reader = Cursor::new(&content);
    let Ok(ms) = MediaSource::seekable(reader) else {
        return ;
    };
    let iter: Result<ExifIter, _> = parser.parse(ms);
    if let Ok(iter) = iter {
        let _ = iter.parse_gps_info();
        for i in iter {
            let s = i;
            s.tag_code();
            s.get_value();
            let _ = s.get_result();
            s.tag();
            s.ifd_index();
            s.has_value();
        }
    }

    let reader = Cursor::new(&content);
    let Ok(ms) = MediaSource::seekable(reader) else {
        return ;
    };
    let _: Result<TrackInfo, _> = parser.parse(ms);
}

panics here

thread 'main' panicked at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/skip.rs:99:46:
called `Result::unwrap()` on an `Err` value: TryFromIntError(())
stack backtrace:
   0: rust_begin_unwind
             at /rustc/5ec7d6eee7e0f5236ec1559499070eaf836bc608/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/5ec7d6eee7e0f5236ec1559499070eaf836bc608/library/core/src/panicking.rs:76:14
   2: core::result::unwrap_failed
             at /rustc/5ec7d6eee7e0f5236ec1559499070eaf836bc608/library/core/src/result.rs:1699:5
   3: core::result::Result<T,E>::unwrap
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1104:23
   4: <nom_exif::skip::Seekable as nom_exif::skip::Skip<R>>::skip_by_seek
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/skip.rs:99:30
   5: nom_exif::parser::BufParser::clear_and_skip
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/parser.rs:235:20
   6: nom_exif::parser::BufParser::load_and_parse_with_offset
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/parser.rs:198:29
   7: nom_exif::parser::BufParser::load_and_parse
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/parser.rs:166:9
   8: <nom_exif::video::TrackInfo as nom_exif::parser::ParseOutput<R,S>>::parse
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/parser.rs:317:26
   9: nom_exif::parser::MediaParser::do_parse
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/parser.rs:458:19
  10: nom_exif::parser::MediaParser::parse
             at /home/runner/.cargo/git/checkouts/nom-exif-cf4dd29e16c043e1/d29b214/src/parser.rs:447:19
  11: nom_exif::check_file
             at /home/runner/work/Automated-Fuzzer/Automated-Fuzzer/src/crates/nom_exif/src/main.rs:88:35
  12: nom_exif::main
             at /home/runner/work/Automated-Fuzzer/Automated-Fuzzer/src/crates/nom_exif/src/main.rs:24:9
  13: core::ops::function::FnOnce::call_once
             at /home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5

crash-7d2528cfb4f2f957f88032d5063dc341c62559a3_minimized.zip

nom-exif binary to test is available here - https://github.com/qarmin/Automated-Fuzzer/releases/download/Nightly/nom_exif.7z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant