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 ObjectNotFound in src/document.rs:446:83 #301

Closed
qarmin opened this issue Aug 13, 2024 · 0 comments · Fixed by #310
Closed

Panic ObjectNotFound in src/document.rs:446:83 #301

qarmin opened this issue Aug 13, 2024 · 0 comments · Fixed by #310
Labels

Comments

@qarmin
Copy link

qarmin commented Aug 13, 2024

thread 'main' panicked at /home/rafal/.cargo/git/checkouts/lopdf-0013854ec52a6141/c25cef3/src/document.rs:446:83:
called `Result::unwrap()` on an `Err` value: ObjectNotFound
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/core/src/panicking.rs:74:14
   2: core::result::unwrap_failed
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/core/src/result.rs:1679:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/core/src/result.rs:1102:23
   4: lopdf::document::Document::get_page_resources
             at /home/rafal/.cargo/git/checkouts/lopdf-0013854ec52a6141/c25cef3/src/document.rs:446:13
   5: lopdf::document::Document::get_page_fonts
             at /home/rafal/.cargo/git/checkouts/lopdf-0013854ec52a6141/c25cef3/src/document.rs:478:45
   6: lopdf::parser_aux::<impl lopdf::document::Document>::extract_text
             at /home/rafal/.cargo/git/checkouts/lopdf-0013854ec52a6141/c25cef3/src/parser_aux.rs:71:25
   7: lopdf::check_file
             at /home/rafal/Projekty/Rust/run_command_for_every_file/src/crates/lopdf/src/main.rs:41:29
   8: lopdf::main
             at /home/rafal/Projekty/Rust/run_command_for_every_file/src/crates/lopdf/src/main.rs:23:9
   9: core::ops::function::FnOnce::call_once
             at /rustc/7120fdac7a6e55a5e4b606256042890b36067052/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Aborted (core dumped)

code

fn check_file(file_path: &str) {
    let Ok(content) = fs::read(file_path) else {
        return;
    };
    let cursor = Cursor::new(content);
    match Document::load_from(cursor) {
        Ok(mut document) => {
            let pages = document.get_pages();

            let mut doc_clone = document.clone();
            doc_clone.decompress();

            for (i, _) in pages.iter().enumerate() {
                let page_number = (i + 1) as u32;
                let _text = document.extract_text(&[page_number]);
            }

            let _ = document.save_to(&mut Cursor::new(Vec::new()));
        }
        Err(err) => {
            eprintln!("Error reading PDF contents: {}", err)
        }
    }
}

file - crash.pdf.zip

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

Successfully merging a pull request may close this issue.

2 participants