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

Use later value for duplicate xref entries in PdfParser #7102

Merged
merged 1 commit into from Apr 29, 2023

Conversation

radarhere
Copy link
Member

Resolves #7084

The issue attempts to append an image to a PDF, but Pillow raises an error, "xref entry duplicated (and not identical)". This error was added in #2965 with the rest of the PDF appending functionality.

Reading https://blog.idrsolutions.com/what-are-pdf-xref-tables/ to learn more about xref tables, I found

it is possible for a PDF file to contain several xref tables and the later values are used.

And indeed, skipping past the duplicate value fixes the issue. We're already using the later value, because Pillow is reading the trailers in reverse order.

I created the test image using Pillow, modified the xref tables so that there is a duplicate entry with a different value, and then asserted that the later value, 1197, is used rather than the earlier value, 1196.

@hugovk hugovk merged commit 380a927 into python-pillow:main Apr 29, 2023
57 of 58 checks passed
@radarhere radarhere deleted the xref_table branch April 29, 2023 20:21
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

Successfully merging this pull request may close these issues.

PIL.PdfParser.PdfFormatError: xref entry duplicated (and not identical)
2 participants