Repository navigation
fix(pdf): stop taking the bytes /JS in image data for JavaScript - #31
Merged
Merged
Conversation
The name scan added in 21fd789 took either /JavaScript or /JS anywhere in the file for a script. /JS is three bytes, and compressed image data spells any three bytes by chance: about once in 24 MB of random bytes, and about once in 2 MB of the ASCII85 text ReportLab writes its streams in. Of 689 ordinary PDFs, 27 were refused as "a PDF with JavaScript", scanned books and newspapers among them, and pdfinfo found a script in none. /JS now counts only in a file that also spells /Rendition. A script needs /JavaScript as the type of its action or as the key of the document's script table; the rendition action is the one other dictionary in ISO 32000-1 with a JS entry (Table 214), and its type is not /JavaScript. All 27 files are no longer refused for JavaScript, and no other verdict among the 689 changed. Skipping the bytes of streams was not an option: the cross-reference table may point into another object's stream, and poppler reads an action placed there. The corpus gains that file, a script on a rendition action, and a scan whose image data spells /JS(. 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.
sillybos refused ordinary scanned PDFs as "a PDF with JavaScript" when they held none. This stops it.
The flaw
Besides asking
pdfinfo, the check scans the file's bytes for the names/JavaScriptand/JS, because poppler before 26 does not report a script on an open-document action (21fd789)./JSis three bytes, and compressed image data spells any three bytes by chance:/JSabout once inOf 689 ordinary PDFs on one machine, 27 were refused for JavaScript. All 27 matched through
/JSalone, andpdfinfofound a script in none. They include scanned books, digitised newspapers and searchable PDFs written with ReportLab. The chance grows with the size of the file, so the longer the scan, the likelier the refusal.The fix
/JSnow counts only in a file that also spells/Rendition./JavaScriptalone still counts, as before./JavaScriptin one of two places: as the type of the action that carries it, or as the key of the document's script name tree.JSentry to exactly two dictionaries: the JavaScript action (Table 217) and the rendition action (Table 214). The rendition action's type is/Rendition, so/JavaScriptwould not find its script. That is the one case/JSadds.Skipping the bytes of streams would have been the obvious fix, and it would have opened a hole. A reader finds an object where the cross-reference table says it is, and the table may point into the middle of another object's stream. poppler 26.04 reads a JavaScript action placed there and reports it. The corpus now holds that file, so the scan still has to find it.
What it changes
/JSkey is in plain bytes while its type name is reached through a reference into a compressed object stream. A file could already hide the whole action in such a stream, which the README says is not seen, so this gives a hostile file nothing it lacked.fix, like the commit that introduced the scan. It refuses nothing new.Tests
/JS(passes underDEFAULTandSTRICT. It fails onmain.pdfinforeporting them./Renditions,/JSON) among them.ruff,mypy,uv lock --check, the docs build and the advisory record check pass.🤖 Generated with Claude Code