Skip to content

Conversation

@yob
Copy link
Owner

@yob yob commented Aug 4, 2025

These two decryption classes assume that the input string:

  • has a bytesize that is a multiple of 16
  • is at least 32 bytes long

I've had very few reports of errors decrypting PDFs so I guess those assumptions hold true for the majority of PDFs in the wild. However in the specific case of a 16 byte input, both these classes would throw an exception from OpenSSL:

OpenSSL::Cipher#final': wrong final block length (OpenSSL::Cipher::CipherError)

First reported in #560 by @gdzevo.

I'd love to have some tests for these, but generating the input data of different lengths will take some time. In the interim, I'll land the fix.

These two decryption classes assume that the input string:

* has a bytesize that is a multiple of 16
* is at least 32 bytes long

I've had very few reports of errors decrypting PDFs so I guess those assumptions hold
true for the majority of PDFs in the wild. In the specific case of a 16 byte input, both
these classes would throw an exception from OpenSSL:

    OpenSSL::Cipher#final': wrong final block length (OpenSSL::Cipher::CipherError)

First reported in #560

I'd love to have some tests for these, but generating the input data of different
lengths will take some time. In the interim, I'll land the fix.
@yob yob force-pushed the avoid-crash-on-16byte-encrypted-value branch from 4c8e36c to a228aca Compare August 4, 2025 13:33
@yob yob merged commit a402f52 into main Aug 4, 2025
1 check passed
@yob yob deleted the avoid-crash-on-16byte-encrypted-value branch August 4, 2025 13:36
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 14, 2025
2.15.0 (2025-08-13)

* Overhaul sorbet types, moving from an external RBI file to inline comments
  in RBS syntax

  - multiple PRs, but mainly yob/pdf-reader#562

  - See https://railsatscale.com/2025-04-23-rbs-support-for-sorbet/

  - No impact expected for most users, but projects that use sorbet may find
    subtle changes in the RBI file that is shipped with the gem

* Relax version requirements for dependency afm, allow 1.x
  (yob/pdf-reader#557)

* Improve text positioning logic in some PDFs
  (yob/pdf-reader#554)

* Multiple fixes for encrypted files

  - Some files with passwords > 32 bytes long
    (yob/pdf-reader#555)

  - Some files that contain cipher text with a 16 byte IV and no further
    blocks (yob/pdf-reader#561)

  - Some files that encrypted data with no padding
    (yob/pdf-reader#564)

* Add jruby 10 to CI matrix (yob/pdf-reader#552)
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