Conversation
Implement step (g) of PDF 32000-1:2008 Algorithm 2: when R>=4 and /EncryptMetadata is false, append 0xFFFFFFFF to the MD5 hash before deriving the encryption key. Without this, AES-128 PDFs with cleartext metadata (common from e-signature tools) fail with "invalid password" even when the actual password is empty. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
initEncryptnever read the/EncryptMetadataentry, so PDFs encrypted with the standard security handler (V=4,R=4, AES-128) that set/EncryptMetadata falsefailed withencrypted PDF: invalid password, even when the actual password is empty.Per PDF 32000-1:2008 §7.6.3.3, Algorithm 2, step (g): security handlers of revision 4 or greater must pass 4 bytes with the value
0xFFFFFFFFto the MD5 hash after the document ID, if document metadata is not being encrypted. This step was missing entirely, so the derived key never matched the file's storedUvalue.This encryption combination (AES-128 content encryption with cleartext metadata for indexing) is common in e-signature/contract-export tools (DocuSign, Adobe Sign, PandaDoc, etc.), so any signed PDF exported that way failed to open.
Originally reported at ledongthuc/pdf#82; filing here since this fork is the actively maintained one.
Changes
read.go: implement step (g) of Algorithm 2 — append0xFFFFFFFFto the MD5 hash whenR >= 4andEncryptMetadatais explicitlyfalse.read_test.go/testdata/encrypted_metadata_false.pdf: regression test using a minimal repro PDF (empty user/owner password,V=4,R=4, AES-128,EncryptMetadata false).Test plan
go build ./...go vet ./...go test ./...— all pass, including newTestOpenEncryptedMetadataFalse