Repository navigation
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Crypt-filter selection remains incorrect for omitted or non-StdCF stream filters.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Adds crypt-filter key-length fallback for V4 PDFs missing top-level /Length.
Changes:
- Derives bit length from crypt-filter
/Length. - Applies fallback in Python and Perl extractors.
| File | Description |
|---|---|
run/pdf2john.py |
Adds crypt-filter length resolution. |
run/lib/PDF.pm |
Propagates StdCF length into hash generation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
kholia
pushed a commit
to kholia/john
that referenced
this pull request
Sep 30, 2026
Address Copilot review comments on PR openwall#6043: - The PDF spec says /StmF and /StrF default to /Identity (no encryption), not /StdCF. The previous code assumed /StdCF when /StmF was absent, which could read an unrelated filter entry and emit a wrong key length. - The Perl path hard-coded 'StdCF' instead of resolving the actual filter name from $$encrypt{StmF}, making the two extractors inconsistent. Both pdf2john.py and PDF.pm now iterate over StmF then StrF, skip any /Identity entry, and use the first filter that carries a /Length value. The CF /Length (bytes) → bits multiplication is unchanged. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
kholia
force-pushed
the
fix-pdf2john-v4-length
branch
from
September 30, 2026 06:56
b6eafef to
e97a3f7
Compare
kholia
force-pushed
the
fix-pdf2john-v4-length
branch
from
September 30, 2026 06:57
e97a3f7 to
cea192b
Compare
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

PDF 1.4+ (V4) allows the encryption dictionary to omit the top-level /Length entry when the key length is specified only inside the applicable crypt filter (CF → StmF filter → /Length). The PDF spec (§3.5) states that the top-level /Length is optional for V2 and V3; in practice some generators (e.g. PDFsharp 6.2.0 / Aspose) also omit it for V4 and rely only on the CF /Length.
Both extractors incorrectly defaulted to 40 bits in that case, causing JtR to treat the document as 40-bit RC4 and fail to crack even when the true algorithm is AES-128.
Fix: when /Length is absent at the top level and V==4, read the key length from the crypt filter identified by /StmF (defaulting to /StdCF). The CF /Length is in bytes; multiply by 8 to get bits.
pdf2john.py: derived via encrypt_dict → /CF → /StmF filter → /Length*8. PDF.pm (pdf2john.pl): fill in $$encrypt{Length} at the point where the CF is already validated, so all downstream uses (hash printf and RC4 key derivation) automatically pick up the correct value.
Fixes #6033