Repository navigation
fix(pdf): see a name in a PDF wherever a chunk boundary falls - #32
Merged
Merged
Conversation
The scan for names reads the file a megabyte at a time and carried the last 32 bytes of each chunk into the next, "longer than the longest escaped spelling of the name". That was true of /Launch, the only name when it was written. /JBIG2Decode with every letter escaped is 34 bytes and /CCITTFaxDecode 43, so one that started 33 bytes before a boundary was in neither window whole and went unseen: a policy that refuses JBIG2 passed the file. What is carried is now as long as the longest pattern, which is longer than any spelling it matches, and comes from the window, so a name longer than a chunk is seen too. A name that ended exactly where a chunk did was also counted before the next byte was known, so /Launcher split after the h was a launch action. Such a match now waits for the next chunk, and counts if the file ends there. Only a policy that refuses a codec could be got round; the names the default looks for all fit in 32 bytes. All 689 PDFs measured for 6.0.2 get the same verdict. Co-authored-by: Yvette Mankerian <yvettekm@gmail.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.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.
The scan that finds names in a PDF's bytes could miss one that straddles the boundary between two reads, and could miscount one that ends exactly on it.
The two flaws
The scan reads the file a megabyte at a time and carries the end of each chunk into the next, so that a name across the boundary is seen whole.
/Launch, the only name when the line was written. With every letter written as a#xxescape,/JBIG2Decodeis 34 bytes and/CCITTFaxDecodeis 43. One that starts 33 bytes before a boundary is whole in neither window, so a policy that refuses JBIG2 passed the file./Launcher, split after theh, was reported as a launch action.The fix
Who was exposed
Only a policy that refuses an image codec (
pdf_image_codecs), which the default does not. The names the default looks for (/Launch,/JavaScript,/JS,/Rendition) all fit in 32 bytes however they are escaped, so no launch action or script was ever missed this way.Typed as a
fix. It refuses a crafted file that passed before, but only under a policy that had already asked for that file to be refused.Tests
main./Launchfollowed across a boundary byer,2and#65r; several names found in different chunks.ruff,mypy,uv lock --checkand the docs build pass.🤖 Generated with Claude Code