Repository navigation
BUG: Treat an empty /Filter array as no filter when extracting images - #4026
Merged
Merged
Conversation
_xobj_to_image() checked only the type of the /Filter entry and then indexed it with -1, so an image whose /Filter is an empty array raised 'IndexError: list index out of range', which made page.images unusable for the whole page. An empty array carries the same meaning as a missing /Filter entry - no filter is applied - so the image now takes the same unfiltered path it would take without the entry.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4026 +/- ##
==========================================
+ Coverage 97.89% 98.00% +0.11%
==========================================
Files 57 57
Lines 10869 11154 +285
Branches 2032 2095 +63
==========================================
+ Hits 10640 10932 +292
+ Misses 127 124 -3
+ Partials 102 98 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stefan6419846
approved these changes
Aug 27, 2026
stefan6419846
added a commit
that referenced
this pull request
Sep 4, 2026
## What's new ### Security (SEC) - Limit value for Roman numerals (#4047) by @stefan6419846 ### New Features (ENH) - _cmap.py: Also parse encoding for embedded CFF Type1 fonts (#4032) by @PJBrs ### Performance Improvements (PI) - Cache repeated text extraction character lookups (#4036) by @petermik68-sudo ### Bug Fixes (BUG) - Treat an empty /Filter array as no filter when extracting images (#4026) by @Anai-Guo - Detect a duplicate dictionary key whose first value is falsy (#4024) by @devYRPauli - Make is_open=False collapse outline items (#3998) by @SomSamantray ### Robustness (ROB) - Multiple changes for wrong inputs by @RavSinghChandan - Skip trailing duplicate %%EOF markers when locating startxref (#4015) by @Anai-Guo - Do not crash on a non-array destination (#3976) by @eeshsaxena - Handle annotations without subtype during merge (#3999) by @Nexlu1 ### Documentation (DOC) - Use AnnotationFlag enum instead of plain integers (#3997) by @RavSinghChandan ### Code Style (STY) - Multiple small changes detected from test runs by @RavSinghChandan [Full Changelog](6.16.2...6.17.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4025.
Problem
_xobj_to_image()reads the/Filterentry and then takes its last element:The check only confirms that the value is a list, and then assumes it can be
indexed with
-1. For an image whose/Filteris an empty array that raisesIndexError: list index out of range, exactly as reported:Because
page.imagesbuilds its id list eagerly, the failure is not limited tothe offending image — iterating
page.imagesraises for the whole page.Fix
An empty array carries the same meaning as a missing
/Filterentry: no filteris applied. The lookup is now skipped when the array is empty, so the image
takes the same unfiltered path it would take with no
/Filterkey at all.Testing
tests/generic/test_image_xobject.py::test_xobj_to_image__empty_filter_arraybuilds the minimal image XObject with
/Filter []and asserts the result isbyte-identical to the same XObject with no
/Filterentry.Verified locally:
IndexError: list index out of rangeat thefilters[-1]line;tests/generic/test_image_xobject.pyis 27 passed;ruffandmypy(1.17.1, the pinned pre-commit revision) are clean on bothchanged files.
The remaining failures in
tests/test_images.py/tests/test_filters.pyon mymachine are pre-existing
FileNotFoundErrors for network fixtures — identicalcounts (37 failed / 130 passed) with and without this patch.
Note on the base
My fork is 68 commits behind and I currently cannot push a branch based on the
newer
main, so this branch is built on the fork's own tip. The merge base isf6287faand the diff againstmainis exactly the two files above (+18/-1) —no unrelated drift is included. I re-ran the tests,
ruffandmypyagainstboth
mainand the fork tip; both are green. Happy to rebase if you prefer.🤖 Generated with Claude Code