Skip to content

fix(security): truncate misaligned AES ciphertext instead of throwing#29

Open
ntedvs wants to merge 1 commit intoLibPDF-js:mainfrom
ntedvs:fix/aes-misaligned-ciphertext
Open

fix(security): truncate misaligned AES ciphertext instead of throwing#29
ntedvs wants to merge 1 commit intoLibPDF-js:mainfrom
ntedvs:fix/aes-misaligned-ciphertext

Conversation

@ntedvs
Copy link

@ntedvs ntedvs commented Feb 17, 2026

Summary

Fixes #28

aesDecrypt threw when ciphertext length wasn't a multiple of 16 bytes, crashing PDF.load() entirely for corrupted encrypted PDFs. Now truncates to the nearest block boundary and decrypts what's available.

aesDecryptWithIv keeps its strict validation since it's used for key derivation where misalignment is a real error.

Note

decryptObject in document-parser.ts still lacks a general try-catch for other decryption failures (e.g. PKCS#7 padding errors). That's a pre-existing gap, not introduced here, but worth addressing separately.

Test plan

  • Truncation of misaligned ciphertext recovers valid data
  • Sub-block-size ciphertext returns empty instead of throwing

@vercel
Copy link
Contributor

vercel bot commented Feb 17, 2026

@ntedvs is attempting to deploy a commit to the mythie's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Slightly corrupted pdfs throw on parsing

1 participant