Skip to content

BUG: Default decode_parms to a DictionaryObject - #3971

Merged
stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:fix-null-decode-parms
Aug 19, 2026
Merged

stefan6419846 merged 2 commits into
py-pdf:mainfrom
RavSinghChandan:fix-null-decode-parms

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

decode_stream_data defaults the per-filter decode parameters to
({},) * len(filters). The decoders take
Optional[Union[DictionaryObject, IndirectObject]], and a plain {} is not
a DictionaryObject, so any stream without an explicit /DecodeParms hands
them the wrong type. A runtime protocol check rejects it; static checking
never noticed because the value flows through stream.get, which returns Any.

DictionaryObject() is an empty mapping and satisfies the annotation, so the
substitution is behaviour-neutral — the same pattern is already used a few
lines above in decode.

Accounts for 5 of the failures in test_generic under make testtype; they go
to 0. Added a test that fails on main.

`decode_stream_data` defaults the per-filter decode parameters to
`({},) * len(filters)`. The decoders take
`Optional[Union[DictionaryObject, IndirectObject]]`, and a plain `{}` is
not a `DictionaryObject`, so any stream without an explicit
`/DecodeParms` hands them the wrong type. A runtime protocol check
rejects it; static checking never noticed because the value flows
through `stream.get`, which returns `Any`.

`DictionaryObject()` is an empty mapping and satisfies the annotation, so
the substitution is behaviour-neutral. The same pattern is already used a
few lines above in `decode`.

Accounts for 5 of the failures in test_generic under `make testtype`;
they go to 0. Added a test that fails on main.
@codecov

codecov Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.94%. Comparing base (1bce7a7) to head (06d6a6c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3971   +/-   ##
=======================================
  Coverage   97.94%   97.94%           
=======================================
  Files          57       57           
  Lines       11031    11031           
  Branches     2065     2065           
=======================================
  Hits        10804    10804           
  Misses        126      126           
  Partials      101      101           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RavSinghChandan RavSinghChandan changed the title UG: Default decode_parms to a DictionaryObject BUG: Default decode_parms to a DictionaryObject Aug 16, 2026
Comment thread pypdf/filters.py Resolved
Comment thread tests/test_filters.py Resolved
Comment thread tests/test_filters.py Resolved
mock.patch.object on FlateDecode.decode replaces the custom subclass, and
the call args carry what the decoder received.
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Dropped the comment, and swapped the custom subclass for mock.patch.object on
FlateDecode.decode - the call args carry what the decoder received, so the test
is a lot shorter now.

On whether it's needed at all: I'd lean towards keeping it. If the default goes
back to a plain {} the test fails, so it does pin the thing being fixed. But
it's your call - happy to drop it if you'd rather not carry a test for a type
detail.

@stefan6419846
stefan6419846 merged commit b45aeba into py-pdf:main Aug 19, 2026
20 checks passed
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.

2 participants