Skip to content

ROB: Fix AESV2 decryption when /Length missing in encrypt dict#3629

Merged
stefan6419846 merged 1 commit intopy-pdf:mainfrom
dmitry-kostin:fix-aesv2-length-from-cf
Feb 6, 2026
Merged

ROB: Fix AESV2 decryption when /Length missing in encrypt dict#3629
stefan6419846 merged 1 commit intopy-pdf:mainfrom
dmitry-kostin:fix-aesv2-length-from-cf

Conversation

@dmitry-kostin
Copy link
Contributor

@dmitry-kostin dmitry-kostin commented Feb 4, 2026

Summary

  • Fix decryption of AESV2 encrypted PDFs when /Length is missing in the main encrypt dict
  • For V=4 encryption with AESV2, read key length from the Crypt Filter dict instead

Test plan

  • Added test case with PDF that has no /Length in encrypt dict
  • All existing encryption tests pass
  • Pre-commit hooks pass

Fixes #3628

@dmitry-kostin dmitry-kostin changed the title Fix AESV2/AESV3 decryption when /Length missing in encrypt dict BUG: Fix AESV2/AESV3 decryption when /Length missing in encrypt dict Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3629   +/-   ##
=======================================
  Coverage   97.39%   97.39%           
=======================================
  Files          55       55           
  Lines        9852     9855    +3     
  Branches     1800     1801    +1     
=======================================
+ Hits         9595     9598    +3     
  Misses        151      151           
  Partials      106      106           

☔ View full report in Codecov by Sentry.
📢 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.

@dmitry-kostin dmitry-kostin force-pushed the fix-aesv2-length-from-cf branch from 0c4d5e1 to 27eeba4 Compare February 4, 2026 15:38
@dmitry-kostin dmitry-kostin changed the title BUG: Fix AESV2/AESV3 decryption when /Length missing in encrypt dict BUG: Fix AESV2 decryption when /Length missing in encrypt dict Feb 4, 2026
@stefan6419846
Copy link
Collaborator

Thanks for the PR. Could you please check whether we are able to keep full coverage? Additionally, please do not use type ignores unless really required, and if required only with specific error codes.

@dmitry-kostin dmitry-kostin force-pushed the fix-aesv2-length-from-cf branch from 27eeba4 to 06aa790 Compare February 4, 2026 17:11
@dmitry-kostin
Copy link
Contributor Author

Okay thanks, refactored to hit full test coverage - though this version feels a bit less readable to me
Also changed # type: ignore to # type: ignore[index] - is that what you meant by specific error codes?

@dmitry-kostin dmitry-kostin force-pushed the fix-aesv2-length-from-cf branch from 06aa790 to f08027c Compare February 5, 2026 14:49
@stefan6419846 stefan6419846 changed the title BUG: Fix AESV2 decryption when /Length missing in encrypt dict ROB: Fix AESV2 decryption when /Length missing in encrypt dict Feb 6, 2026
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@stefan6419846 stefan6419846 merged commit 3b94ce8 into py-pdf:main Feb 6, 2026
19 checks passed
stefan6419846 added a commit that referenced this pull request Feb 8, 2026
## What's new

### Deprecations (DEP)
- Deprecate support for abbreviations in decode_stream_data (#3617) by @stefan6419846

### New Features (ENH)
- Add ability to add font resources for 14 Adobe Core fonts in text widget annotations (#3624) by @PJBrs

### Bug Fixes (BUG)
- Avoid invalid load for ICCBased FlateDecode images in mode 1 (#3619) by @stefan6419846

### Robustness (ROB)
- Fix AESV2 decryption when /Length missing in encrypt dict (#3629) by @dmitry-kostin
- Fix merging when annotations point to NullObject (#3613) by @stefan6419846
- Check for `self._info` being None in `compress_identical_objects` (#3612) by @stefan6419846

[Full Changelog](6.6.2...6.7.0)
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.

AESV2 decryption fails when /Length missing in encrypt dict

2 participants