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 on invalid input to pdf::file::FileOptions::load #211

Closed
MinghuaWang opened this issue Feb 6, 2024 · 0 comments
Closed

Panic on invalid input to pdf::file::FileOptions::load #211

MinghuaWang opened this issue Feb 6, 2024 · 0 comments

Comments

@MinghuaWang
Copy link

Describe the bug

Panic could be triggered when passing pdf::file::FileOptions::load with invalid input. Panic info is shown below:
thread 'main' panicked at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/primitive.rs:767:33:
byte index 2 is not a char boundary; it is inside 'ߧ' (bytes 1..3) of <ߧ0101213085485+01*01'* /GgaBcqf'A<40110612185925+01'01'

Full stack backtrace:

   0: rust_begin_unwind
             at /rustc/07688726805d5db0a4bca445a6651d09708041ea/library/std/src/panicking.rs:617:5
   1: core::panicking::panic_fmt
             at /rustc/07688726805d5db0a4bca445a6651d09708041ea/library/core/src/panicking.rs:67:14
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
             at /rustc/07688726805d5db0a4bca445a6651d09708041ea/library/core/src/str/mod.rs:87:9
   4: core::str::traits::<impl core::slice::index::SliceIndex<str> for core::ops::range::Range<usize>>::index
             at /rustc/07688726805d5db0a4bca445a6651d09708041ea/library/core/src/str/traits.rs:235:21
   5: core::str::traits::<impl core::ops::index::Index<I> for str>::index
             at /rustc/07688726805d5db0a4bca445a6651d09708041ea/library/core/src/str/traits.rs:61:9
   6: <pdf::primitive::Date as pdf::object::Object>::from_primitive
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/primitive.rs:767:33
   7: <core::option::Option<T> as pdf::object::Object>::from_primitive
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/object/mod.rs:656:24
   8: <pdf::object::types::InfoDict as pdf::object::FromDict>::from_dict
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/object/types.rs:1551:10
   9: <pdf::object::types::InfoDict as pdf::object::Object>::from_primitive
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/object/types.rs:1551:10
  10: <core::option::Option<T> as pdf::object::Object>::from_primitive
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/object/mod.rs:656:24
  11: <pdf::file::Trailer as pdf::object::FromDict>::from_dict
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/file.rs:626:10
  12: <pdf::file::Trailer as pdf::object::Object>::from_primitive
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/file.rs:626:10
  13: pdf::file::File<B,OC,SC,L>::load_data
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/file.rs:579:26
  14: pdf::file::FileOptions<OC,SC,L>::load
             at /DATA2/dev/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/pdf-0.9.0/src/file.rs:562:9
  15: pdf_poc::main
             at ./src/main.rs:4:21
  16: core::ops::function::FnOnce::call_once
             at /rustc/07688726805d5db0a4bca445a6651d09708041ea/library/core/src/ops/function.rs:250:5

Expected behavior

Not panic. It could be an error reported to the users.

Test environment:

Version: pdf = "0.9.0"
OS: Ubuntu 20.04, 64 bit
Target triple: x86_64-unknown-linux-gnu
Rustc version: rustc 1.73.0-nightly (076887268 2023-08-17)

To Reproduce

It can be reproduced with the following program:

fn main() {
    let p = "crash.pdf";
    if let Ok(data) = std::fs::read(p) {
        if let Ok(file) = pdf::file::FileOptions::cached().load(data.as_slice()) {
            for idx in 0..file.num_pages() {
                let _ = file.get_page(idx);
            }
        }
    }
}

crash.pdf is attached:
crash.pdf.zip

@s3bk s3bk closed this as completed in b06cfdf Feb 6, 2024
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