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

Fix issue #86 by upgrade to MuPDF 1.24.4 #97

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- dev
pull_request:
workflow_dispatch:

Expand All @@ -18,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"
fetch-depth: 500
- uses: dtolnay/rust-toolchain@stable
- run: cargo check
Expand All @@ -33,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"
fetch-depth: 500
- uses: dtolnay/rust-toolchain@stable
- name: Install LLVM
Expand All @@ -52,36 +53,41 @@ jobs:
- name: Test package mupdf-sys
if: matrix.os == 'ubuntu-latest'
run: cargo package --manifest-path mupdf-sys/Cargo.toml

test-msys:
name: Test Suite (MSYS2)
runs-on: windows-2019
defaults:
run:
shell: msys2 {0}
strategy:
matrix:
include:
- { sys: ucrt64, env: ucrt-x86_64 }
- { sys: ucrt64, env: ucrt-x86_64 }
- { sys: mingw64, env: x86_64 }
# - { sys: mingw32, env: i686 }
- { sys: mingw32, env: i686 }
- { sys: clang64, env: clang-x86_64 }
steps:
- uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.sys}}
install: mingw-w64-${{matrix.env}}-rust base base-devel unzip git
install: mingw-w64-${{matrix.env}}-rust mingw-w64-${{matrix.env}}-clang base base-devel unzip git

- uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"
fetch-depth: 500
- run: cargo test

- run: |
rustc --version --verbose
cargo test

asan:
name: Address Sanitizer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"
fetch-depth: 500
- uses: dtolnay/rust-toolchain@nightly
with:
Expand All @@ -98,7 +104,7 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"
fetch-depth: 500
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@valgrind
Expand Down
13 changes: 10 additions & 3 deletions mupdf-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn build_libmupdf() {
let mut make_flags = vec![
"libs".to_owned(),
format!("build={}", profile),
format!("OUT={}", build_dir.display()),
format!("OUT={}", &build_dir_str),
#[cfg(feature = "sys-lib-freetype")]
"USE_SYSTEM_FREETYPE=yes".to_owned(),
#[cfg(feature = "sys-lib-gumbo")]
Expand Down Expand Up @@ -253,15 +253,15 @@ fn build_libmupdf() {
};
let output = Command::new(make)
.args(&make_flags)
.current_dir(&build_dir)
.current_dir(&build_dir_str)
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.expect("make failed");
if !output.status.success() {
panic!("Build error, exit code {}", output.status.code().unwrap());
}
println!("cargo:rustc-link-search=native={}", build_dir.display());
println!("cargo:rustc-link-search=native={}", &build_dir_str);
println!("cargo:rustc-link-lib=static=mupdf");
// println!("cargo:rustc-link-lib=static=mupdf-pkcs7");
println!("cargo:rustc-link-lib=static=mupdf-third");
Expand Down Expand Up @@ -351,6 +351,13 @@ fn build_libmupdf() {
profile
);
}

if profile == "Debug" {
println!("cargo:rustc-link-lib=dylib=ucrtd");
println!("cargo:rustc-link-lib=dylib=vcruntimed");
println!("cargo:rustc-link-lib=dylib=msvcrtd");
}

println!("cargo:rustc-link-lib=dylib=libmupdf");
println!("cargo:rustc-link-lib=dylib=libthirdparty");
} else {
Expand Down
2 changes: 1 addition & 1 deletion mupdf-sys/mupdf
Submodule mupdf updated 691 files
2 changes: 1 addition & 1 deletion mupdf-sys/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3012,7 +3012,7 @@ void mupdf_pdf_page_set_crop_box(fz_context *ctx, pdf_page *page, fz_rect rect,
{
fz_try(ctx)
{
fz_rect mediabox = pdf_bound_page(ctx, page);
fz_rect mediabox = pdf_bound_page(ctx, page, FZ_MEDIA_BOX);
pdf_obj *obj = pdf_dict_get_inheritable(ctx, page->obj, PDF_NAME(MediaBox));
if (obj)
{
Expand Down
Binary file added tests/files/utf8-error-on-this-file.pdf
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/test_issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ fn test_issue_60_display_list() {
})
.collect();
}

#[test]
fn test_issue_86_invalid_utf8() {
let doc = PdfDocument::open("tests/files/utf8-error-on-this-file.pdf").unwrap();
for (idx, page) in doc.pages().unwrap().enumerate() {
let page = page.unwrap();
let text = page.to_text();
assert!(text.is_ok());
println!("page: {idx}, text: {}", text.unwrap());

let json = page.stext_page_as_json_from_page(1.0);
assert!(json.is_ok());

// Validate JSON parsing
let parsed_json: Result<serde_json::Value, _> = serde_json::from_str(&json.unwrap());
assert!(parsed_json.is_ok());
}
}