J-F-Liu / lopdf

A Rust library for PDF document manipulation.
MIT License
1.67k stars 176 forks source link

Panic when opening pdf file #287

Closed qarmin closed 3 months ago

qarmin commented 4 months ago

Code

fn check_file(file_path: &str) {
    match Document::load(file_path) {
        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]);
            }

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

File - compressed.zip

thread '<unnamed>' panicked at /home/runner/.cargo/git/checkouts/lopdf-0013854ec52a6141/2cf9f98/src/object_stream.rs:43:63:
range start index 3026 out of range for slice of length 3016
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::slice::index::slice_start_index_len_fail
   3: rayon::iter::plumbing::Producer::fold_with
   4: rayon::iter::plumbing::bridge_producer_consumer::helper
   5: rayon_core::join::join_context::{{closure}}
   6: rayon::iter::plumbing::bridge_producer_consumer::helper
   7: rayon_core::join::join_context::{{closure}}
   8: rayon::iter::plumbing::bridge_producer_consumer::helper
   9: rayon_core::join::join_context::{{closure}}
  10: rayon::iter::plumbing::bridge_producer_consumer::helper
  11: rayon::iter::extend::<impl rayon::iter::ParallelExtend<(K,V)> for alloc::collections::btree::map::BTreeMap<K,V>>::par_extend
  12: rayon::iter::from_par_iter::collect_extended
  13: lopdf::object_stream::ObjectStream::new
  14: lopdf::reader::Reader::read::{{closure}}
  15: rayon::iter::plumbing::Folder::consume_iter
  16: rayon::iter::plumbing::bridge_producer_consumer::helper
  17: rayon_core::join::join_context::{{closure}}
  18: rayon_core::registry::in_worker
  19: rayon::iter::plumbing::bridge_producer_consumer::helper
  20: rayon_core::join::join_context::{{closure}}
  21: rayon_core::registry::in_worker
  22: rayon::iter::plumbing::bridge_producer_consumer::helper
  23: rayon_core::join::join_context::{{closure}}
  24: rayon_core::registry::in_worker
  25: rayon::iter::plumbing::bridge_producer_consumer::helper
  26: rayon_core::join::join_context::{{closure}}
  27: rayon_core::registry::in_worker
  28: rayon::iter::plumbing::bridge_producer_consumer::helper
  29: <rayon_core::job::StackJob<L,F,R> as rayon_core::job::Job>::execute
  30: rayon_core::registry::WorkerThread::wait_until_cold
  31: rayon_core::registry::ThreadBuilder::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

##### Automatic Fuzzer note, output status "Some(101)", output signal "None"