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 image extract #871

Closed
sanbornm opened this issue May 18, 2024 · 8 comments
Closed

Panic on image extract #871

sanbornm opened this issue May 18, 2024 · 8 comments
Assignees

Comments

@sanbornm
Copy link

sanbornm commented May 18, 2024

I'm getting panic: runtime error: index out of range [45675] with length 45675

on pdfcpu/pdfcpu/pkg/pdfcpu/writeImage.go:346. when trying to extract images from PDF.

Is this potentially an off by one error? Maybe it just needs an length check and if it is out of bounds to use the defaulted alpha := uint8(255)?

Linux Arch
6.8.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 28 Apr 2024 15:59:47 +0000 x86_64 GNU/Linux

Commenting out alpha = im.softMask[y*im.w+x] makes my PDF extract images without panic

@sanbornm
Copy link
Author

I think this is the same bug as: #804 sorry for the additional issue.

@hhrutter
Copy link
Collaborator

Perfect!
Could you share this file in order to get this fixed right way?
🙏🏻

@sanbornm
Copy link
Author

Sent via email. I hope that's ok.

@hhrutter
Copy link
Collaborator

The file seems to be corrupt:

out pdfcpu val 2024-rs-excise-q1.pdf
validating(mode=relaxed) 2024-rs-excise-q1.pdf ...
Read: xRefTable failed: pdfcpu: corrupted last xref section

Neither does it open with Adobe Reader or Mac Preview.

@sanbornm
Copy link
Author

Thanks for taking a look. Even though the file is corrupt and only somewhat readable I feel like it shouldn't panic. Especially from using an index out of bounds type error (length should be checked and image skipped?) I could wrap a recover around image extract but would prefer if it didn't panic.

@hhrutter
Copy link
Collaborator

My point was that the attached file got damaged probably during or on the way to the upload.
The error above is an indication for it - it crashes right at the beginning when trying to load the xreftable.

...unless you can also not open this file with Adobe Reader - then it would be corrupt for sure and needs fixing anyways.

@hhrutter
Copy link
Collaborator

This is fixed with the latest commit!

@sanbornm
Copy link
Author

Thank you!!

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

No branches or pull requests

2 participants