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 occurs when call for 'WatermarkContext' #771

Closed
zvzo opened this issue Jan 10, 2024 · 5 comments
Closed

panic occurs when call for 'WatermarkContext' #771

zvzo opened this issue Jan 10, 2024 · 5 comments
Assignees

Comments

@zvzo
Copy link

zvzo commented Jan 10, 2024

version: 0.6.0
os macos 14.2.1

Panic occurs when calling the interface for adding watermarks.

is at the location shown in the screenshot.

Maybe we need to check whether the array is empty? It may also be that my file is not standard. Is the file just a blank pdf file? If necessary, I can send it to you for review.

// WatermarkContext applies wm for selected pages to ctx.
func WatermarkContext(ctx *model.Context, selectedPages types.IntSet, wm *model.Watermark) error {
return pdfcpu.AddWatermarks(ctx, selectedPages, wm)
}

image

@hhrutter
Copy link
Collaborator

Did you check if your file is valid?
pdfcpu validate test.pdf

@zvzo
Copy link
Author

zvzo commented Jan 11, 2024

Did you check if your file is valid? pdfcpu validate test.pdf

# pdfcpu validate /tmp/add_wm_panic_file.pdf
validating(mode=relaxed) /tmp/add_wm_panic_file.pdf ...
validation ok

# pdfcpu validate -mode "strict" /tmp/add_wm_panic_file.pdf
validating(mode=strict) /tmp/add_wm_panic_file.pdf ...
validation ok

looks like valid

@hhrutter
Copy link
Collaborator

ok, please share the file as debugging will be easier.

Thanks for using pdfcpu 💚

@hhrutter
Copy link
Collaborator

The line numbers of your screenshot are not from v0.6.0

I'd like to see add_wm_panic_file.pdf..
It appears to have a page with a corrupt content stream array.

@hhrutter
Copy link
Collaborator

This is fixed with the latest commit.

The consequence of accepting an empty page content array (which is a PDF spec violation)
is that you can't stamp such a page.

I recommend using testdata/empty.pdf or create such file using one of the more popular tools out there.

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