Skip to content

Fix decryption of literal strings#130

Merged
Sharcoux merged 1 commit intocantoo-scribe:masterfrom
onyck:fix-literal-string-decryption
Feb 17, 2026
Merged

Fix decryption of literal strings#130
Sharcoux merged 1 commit intocantoo-scribe:masterfrom
onyck:fix-literal-string-decryption

Conversation

@onyck
Copy link
Copy Markdown

@onyck onyck commented Dec 7, 2025

What?

This PR fixes the decryption of literal strings that contain escape sequences.

Fixes #122.

Why?

The current code decrypts literal strings without processing escape sequences. If an encrypted literal string does contain escape sequences, the decrypted value is nonsense and can cause issues such as #122.

Encrypted literal strings may contain escape sequences according to section 7.3.4.2 of the PDF 1.7 specification, so escape sequences should be resolved prior to decryption.

How?

This PR uses the existing PDFString.asBytes() method to convert the literal string to a byte array while handling escape sequences. The byte array is then decrypted using the cipher transformer.

Testing?

Added and ran unit tests.

New Dependencies?

No

Screenshots

N/A

Suggested Reading?

Yes

Anything Else?

N/A

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
  • I ran the integration tests.
  • I tested my changes in Node, Deno, and the browser.
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • I added/updated doc comments for any new/modified public APIs.
  • My changes work for both new and existing PDF files.
  • I ran the linter on my changes.

@d1c0n
Copy link
Copy Markdown

d1c0n commented Feb 17, 2026

@Sharcoux Do you think it's possible to merge this? I've encountered the problem mentioned in the issue #122 plenty of times. I've tested this PR and it this seems to work ok. I'm not really familiar with the PDF spec or the encryption flow though, I have no idea if this can introduce any problems.

@Sharcoux Sharcoux merged commit 3e6fcd8 into cantoo-scribe:master Feb 17, 2026
1 check passed
@Sharcoux
Copy link
Copy Markdown
Collaborator

Perfect @onyck
Thanks a lot!

@Sharcoux
Copy link
Copy Markdown
Collaborator

Released in v2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In password-protected PDFs, the Registry and Ordering fields of the CIDSystemInfo structure are not being set.

3 participants