From 692cc0544909f9de265219ca890615ef1d0af6d2 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Mon, 2 Nov 2026 23:34:33 +0000 Subject: [PATCH 1/2] feat: a policy on the codecs a PDF's images may use, found by filter name `pdf_image_codecs` names which of JPEG, JPEG 2000, JBIG2 and CCITT a PDF's images may be coded with. Both presets allow all four: scanners and the archives that derive PDFs from scans write them, and five of the seven PDFs in Tetrak OCR's corpus are JBIG2-coded. A policy that knows its source never writes one refuses it by name. The codec is found by the filter's name in the bytes, the way a launch action is, because `pdfimages -list` opens a JPX stream with OpenJPEG just to describe it, which is the decoder's code the check exists to keep from the file. The name scan now also matches an escaped digit, so `/JBIG#32Decode` is seen. The three JBIG2 proposals name the field and its test; the six on embedded fonts move to C, since every searchable PDF embeds a font and a policy refusing them would refuse the text layers it exists to protect. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.1 --- AGENTS.md | 13 +++-- README.md | 14 +++-- docs/advisories/README.md | 17 +++--- docs/advisories/proposed/CVE-2025-27363.json | 8 +-- docs/advisories/proposed/CVE-2025-32365.json | 16 ++++-- docs/advisories/proposed/CVE-2025-9900.json | 35 ------------ docs/advisories/proposed/CVE-2026-102620.json | 8 +-- docs/advisories/proposed/CVE-2026-23865.json | 8 +-- docs/advisories/proposed/CVE-2026-50811.json | 8 +-- docs/advisories/proposed/CVE-2026-93312.json | 16 ++++-- docs/advisories/proposed/CVE-2026-93313.json | 16 ++++-- docs/advisories/proposed/CVE-2026-93314.json | 8 +-- docs/advisories/proposed/CVE-2026-95512.json | 8 +-- docs/api.md | 2 + src/sillybos/__init__.py | 2 + src/sillybos/check.py | 15 ++++++ src/sillybos/cli.py | 10 ++++ src/sillybos/pdf.py | 54 +++++++++++++++---- src/sillybos/policy.py | 28 ++++++++++ tests/corpus.py | 39 ++++++++++++-- tests/test_check.py | 40 +++++++++++++- tests/test_cli.py | 8 +++ 22 files changed, 267 insertions(+), 106 deletions(-) delete mode 100644 docs/advisories/proposed/CVE-2025-9900.json diff --git a/AGENTS.md b/AGENTS.md index 8471fa1..c2583f6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,11 +36,14 @@ code touches it. So: `sillybos/pillow.py`, which is the optional extra. - A PDF is asked about through `pdfinfo` and `pdfdetach` in a subprocess with a timeout. Never add a PDF parser as a dependency, and never read a - PDF's objects with code here. The one thing this code does read from a - PDF's bytes is the *name* of a launch action, by a bounded search for - its spelling (`pdf.py`, `_has_launch_action`), because no poppler tool - reports one; a search for bytes is not a parser, and it must stay that - way. + PDF's objects with code here. The only things this code reads from a + PDF's bytes are *names*, by a bounded search for their spellings + (`pdf.py`, `_names_in`): a launch action, because no poppler tool + reports one, and the filters its images are coded with (DCT, JPX, JBIG2, + CCITT), because the tool that would list them, `pdfimages -list`, opens + a JPX stream with OpenJPEG just to describe it. A search for bytes is + not a parser, and it must stay that way; never add `pdfimages` to the + tools the check runs. - The library has **no runtime dependencies**, and `[project] dependencies` stays `[]`. Everything else goes in an extra. - Every read of a file is bounded by a constant or by the policy, and every diff --git a/README.md b/README.md index bfceeb3..458170a 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ check(path, Policy(formats={"tiff", "pdf"}, max_pages=50)) | `jpeg_frames` | baseline, extended, progressive | the same | How a JPEG's frame may be coded. Lossless, hierarchical and arithmetic frames are legal JPEG that no scanner writes and the decoder's least-exercised code; a lossless frame was the way into a heap overflow in Pillow's JPEG decoder (CVE-2026-112403) | | `allow_encrypted_pdf` | no | no | A scanned book is never encrypted | | `pdf_features` | none | none | Which of JavaScript, forms, attached files and launch actions a PDF may carry. Each makes a viewer do something other than draw the page, and a scanned book has none. Forms are read from `pdfinfo`'s report and attached files from `pdfdetach`'s; a launch action is found by its name in the file, since no poppler tool reports one; JavaScript is looked for both ways | +| `pdf_image_codecs` | jpeg, jpx, jbig2, ccitt | the same | Which codecs a PDF's images may be coded with: JPEG, JPEG 2000 (OpenJPEG), JBIG2 and CCITT fax. Each hands the stream to a decoder of its own inside poppler, and the JBIG2 decoder is where several of its flaws have been (CVE-2025-32365, CVE-2026-93312, CVE-2026-93313). Scanners and the archives that derive PDFs from scans write all four, so both presets allow them; refuse one only when you know your source never writes it. Found by the filter's name in the file, not by `pdfimages -list`, which opens a JPX stream with OpenJPEG just to describe it | | `pdfinfo_timeout` | 30 s | 30 s | How long `pdfinfo` may take before the file is refused | The defaults were set from a real corpus of archival scans (largest page 39 @@ -187,8 +188,9 @@ prints one object per line for a pipeline; `-q` prints only refusals. `pdfinfo` reports the page count, whether it is encrypted, whether it carries JavaScript or a form and, if the count is within the limit, every page's size; `pdfdetach` reports attached files; and a bounded - scan of the bytes finds the name of a launch action, and of JavaScript - that an older poppler does not report, with the `#xx` escapes a name + scan of the bytes finds the name of a launch action, of JavaScript + that an older poppler does not report, and of the filters its images + are coded with (DCT, JPX, JBIG2, CCITT), with the `#xx` escapes a name may hide behind undone. 5. **The limits**, against what the header said. @@ -213,8 +215,12 @@ Say this plainly, because a security library carries an implied promise. - **It does not look inside a PDF beyond what `pdfinfo` reports.** A PDF's structure cannot be read from a fixed header; it has to be parsed, and the parser this library trusts is poppler's, in its own process, with a - timeout. Checks for JavaScript, launch actions, embedded files and forms - (things a scanned book never has) are the next step. + timeout. JavaScript, launch actions, embedded files, forms and the + codecs of its images are found from that report and from names in the + bytes; a name reachable only through an indirect reference inside a + compressed object stream is not seen. `pdfimages -list` would see it, + but it opens a JPEG 2000 stream with OpenJPEG just to describe it, so + this library never runs it. - **It does not validate uploads.** File names, path traversal and zip bombs belong to a web framework's upload handling. This library starts after the file is on disk and asks only whether a decoder may open it. diff --git a/docs/advisories/README.md b/docs/advisories/README.md index 14b8841..d54947d 100644 --- a/docs/advisories/README.md +++ b/docs/advisories/README.md @@ -2,8 +2,8 @@ sillybos stands in front of decoders it does not control. When one of them publishes a security advisory, the question for this library is narrow: -**would a bounded header check, or what `pdfinfo`, `pdfimages -list` or -`pdffonts` report, have kept the triggering file from the decoder?** A +**would a bounded header check, what `pdfinfo` reports, or a name found +in a PDF's bytes have kept the triggering file from the decoder?** A weekly job fetches the advisories and opens an issue for each; a maintainer answers that question and files the issue in a bucket. This page is the procedure. @@ -136,10 +136,13 @@ bucket and the sentence are right, promote it, and if not, edit the file first. A proposal in bucket A, B or B2 cannot be promoted until it names a test that builds the triggering file and checks it is refused: for an A that test usually exists already, and for a B or B2 the policy field and -the corpus case come first, as the next section says. The proposals in -B2 at the time of writing all want one of two coarse PDF policies, on -embedded fonts and on JBIG2 image streams, and the one B wants a ceiling -on a single image dimension. +the corpus case come first, as the next section says. The B2 proposals on +JBIG2 streams name `pdf_image_codecs`, which came out of them; the ones on +embedded fonts were moved to C, because every searchable PDF embeds a +font, so a policy refusing fonts would refuse the text layers it exists to +protect. `pdfimages -list` was found to open a JPX stream with OpenJPEG +just to describe it, which is why the codecs are found by name and that +tool is never run. ## The buckets @@ -150,7 +153,7 @@ answer to the question at the top of this page. |---|---|---| | **A** | Already refused by an existing check: a format outside the four, a frame coding the policy refuses, a size over a limit | Say which check, and close | | **B** | Preventable from a header field our readers can see: a marker, a tag, a chunk, a count, a dimension | A policy field and a hostile corpus case (below), then close when it ships | -| **B2** | Preventable only by a coarse policy on a PDF's contents that `pdfimages -list` or `pdffonts` report: a JBIG2 or JPX stream, an embedded font | The same as B, through the PDF path; note that the policy will be coarse | +| **B2** | Preventable only by a coarse policy on a PDF's contents: the codec of an image, found by its filter's name in the bytes (`pdf_image_codecs`). Not an embedded font: every searchable PDF carries one, so a policy on fonts has no user, and a flaw in the font program is C | The same as B, through the PDF path; note that the policy will be coarse | | **C** | Needs decoding to detect: a flaw in the pixel data, the entropy-coded segment, the font program | Out of this library's reach by design; say so and close. Updating the decoder is the fix | | **D** | Reaches `pdfinfo` itself | Check that the check still fails closed (a timeout or a non-zero exit is a refusal), and close | | **N** | Not reached by opening a file: a command-line tool, a save or encode path, a drawing or font API, a parser that only runs on append | Close | diff --git a/docs/advisories/proposed/CVE-2025-27363.json b/docs/advisories/proposed/CVE-2025-27363.json index 4adbfda..a99f7f5 100644 --- a/docs/advisories/proposed/CVE-2025-27363.json +++ b/docs/advisories/proposed/CVE-2025-27363.json @@ -12,18 +12,18 @@ "fixed": "2.13.1", "reached_by": "open", "trigger": "Rendering a PDF whose embedded font is a TrueType GX or variable font with crafted subglyph structures; FreeType parses the font when poppler draws the text.", - "bucket": "B2", - "finding": "Reached by rendering, through the embedded font. pdffonts reports every embedded font and its type, so a coarse policy refusing embedded fonts, or TrueType fonts, would keep the font from FreeType; a scanned book has no fonts, but a searchable PDF's invisible text layer does, so the policy would be a trade. Not built.", + "bucket": "C", + "finding": "Reached by rendering, through the embedded font. pdffonts reports every embedded font and its type, so a coarse policy refusing embedded fonts, or TrueType fonts, would keep the font from FreeType; a scanned book has no fonts, but a searchable PDF's invisible text layer does, so the policy would be a trade. No policy is built: every searchable PDF embeds a font, Tetrak OCR's own output included (all thirty-eight PDFs in its checkouts carry one), so a policy refusing fonts would refuse the text layers it exists to protect. A flaw in the font program is out of this library's reach; the boxed process is the defence.", "refusal": null, "verified_by": [], "protect": { "general": "Upgrade to FreeType 2.13.1.", - "specific": "Until a policy on embedded fonts exists, render in a boxed process; a PDF with no text layer carries no font for FreeType to parse." + "specific": "Render in a boxed process; a PDF with no text layer carries no font for FreeType to parse." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2025-27363" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. Moved from B2 to C on 2026-11-02, with the finding above." } diff --git a/docs/advisories/proposed/CVE-2025-32365.json b/docs/advisories/proposed/CVE-2025-32365.json index f7e1c52..d90a79f 100644 --- a/docs/advisories/proposed/CVE-2025-32365.json +++ b/docs/advisories/proposed/CVE-2025-32365.json @@ -13,17 +13,23 @@ "reached_by": "open", "trigger": "Rendering a PDF page whose image is a crafted JBIG2 stream.", "bucket": "B2", - "finding": "pdfimages -list reports each image stream's encoding, so a coarse policy refusing JBIG2 streams would keep the stream from the decoder. Some scanners write JBIG2-compressed PDFs, so the policy would refuse real scans too. Not built.", - "refusal": null, - "verified_by": [], + "finding": "Reached by rendering a page whose image is a JBIG2 stream. The image's filter is named in its stream dictionary, which cannot be hidden inside a compressed object stream, so a bounded search of the bytes finds /JBIG2Decode and the policy can refuse the codec by name (pdf_image_codecs). The default allows it: scanners and the archives that derive PDFs from scans write JBIG2 (five of the seven PDFs in Tetrak OCR's corpus). pdfimages -list would report the codec too, but it opens a JPX stream with OpenJPEG just to describe it, so the library does not run it.", + "refusal": { + "check": "pdf_image_codecs", + "default": false, + "setting": "Policy(pdf_image_codecs={\"jpeg\", \"jpx\", \"ccitt\"})" + }, + "verified_by": [ + "tests/test_check.py::TestPdf::test_a_jbig2_pdf_under_a_policy_that_refuses_it" + ], "protect": { "general": "Upgrade to poppler 25.04.0.", - "specific": "Until a policy on image stream encodings exists, render in a boxed process." + "specific": "If nothing you handle is JBIG2-coded, say so in the policy: sillybos --pdf-image-codecs jpeg,jpx,ccitt. Otherwise render in a boxed process." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2025-32365" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. The policy field was named on 2026-11-02." } diff --git a/docs/advisories/proposed/CVE-2025-9900.json b/docs/advisories/proposed/CVE-2025-9900.json deleted file mode 100644 index d4da1ac..0000000 --- a/docs/advisories/proposed/CVE-2025-9900.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "key": "CVE-2025-9900", - "aliases": [], - "library": "libtiff", - "package": "tiff", - "ecosystem": "Debian", - "title": "An abnormally tall TIFF makes libtiff write colour data to an arbitrary address", - "summary": "A flaw was found in Libtiff.", - "published": "2025-09-23", - "severity": 8.8, - "affected": "LibTIFF, as packaged; see the upstream record", - "fixed": null, - "reached_by": "open", - "trigger": "Reading a TIFF whose image height is abnormally large, through libtiff's RGBA image reading.", - "bucket": "B", - "finding": "The height is in the first directory, which sillybos reads. A height large enough to carry the pixel count past max_pixels was already refused; a tall, narrow image within the pixel budget was not, until max_side: every page, frame and tile is now held to it on its longest side (30,000 by default; no scanner writes a side longer than a few tens of thousands of pixels).", - "refusal": { - "check": "max_side", - "default": true, - "setting": "max_side" - }, - "verified_by": [ - "tests/test_check.py::TestHostileFiles::test_a_tall_narrow_tiff" - ], - "protect": { - "general": "Upgrade libtiff to a version that has the fix; the upstream record names it.", - "specific": "Set max_side from your corpus (the longest side of your largest real page, times two or three); sillybos refuses a taller or wider image before libtiff sees it." - }, - "sources": [ - "https://osv.dev/vulnerability/DEBIAN-CVE-2025-9900" - ], - "triaged": "2026-11-01", - "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." -} diff --git a/docs/advisories/proposed/CVE-2026-102620.json b/docs/advisories/proposed/CVE-2026-102620.json index 7b589c3..ed68f78 100644 --- a/docs/advisories/proposed/CVE-2026-102620.json +++ b/docs/advisories/proposed/CVE-2026-102620.json @@ -12,18 +12,18 @@ "fixed": null, "reached_by": "open", "trigger": "Rendering a PDF whose embedded TrueType font makes FoFiTrueType::cvtSfnts overflow.", - "bucket": "B2", - "finding": "Reached through an embedded font that pdffonts would report; as CVE-2026-93314. Not built.", + "bucket": "C", + "finding": "Reached through an embedded font that pdffonts would report; as CVE-2026-93314. No policy is built: every searchable PDF embeds a font, Tetrak OCR's own output included (all thirty-eight PDFs in its checkouts carry one), so a policy refusing fonts would refuse the text layers it exists to protect. A flaw in the font program is out of this library's reach; the boxed process is the defence.", "refusal": null, "verified_by": [], "protect": { "general": "Upgrade poppler to a version that has the fix; the upstream record names it.", - "specific": "Until a policy on embedded fonts exists, render in a boxed process." + "specific": "Render in a boxed process." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-102620" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. Moved from B2 to C on 2026-11-02, with the finding above." } diff --git a/docs/advisories/proposed/CVE-2026-23865.json b/docs/advisories/proposed/CVE-2026-23865.json index d57c643..e1571a5 100644 --- a/docs/advisories/proposed/CVE-2026-23865.json +++ b/docs/advisories/proposed/CVE-2026-23865.json @@ -12,18 +12,18 @@ "fixed": "2.14.2", "reached_by": "open", "trigger": "Rendering a PDF whose embedded OpenType variable font carries crafted HVAR, VVAR or MVAR tables.", - "bucket": "B2", - "finding": "Reached by rendering, through an embedded font that pdffonts would report; as CVE-2025-27363, a coarse policy on embedded fonts would keep it from FreeType, at the cost of refusing searchable PDFs' text layers. Not built.", + "bucket": "C", + "finding": "Reached by rendering, through an embedded font that pdffonts would report; as CVE-2025-27363, a coarse policy on embedded fonts would keep it from FreeType, at the cost of refusing searchable PDFs' text layers. No policy is built: every searchable PDF embeds a font, Tetrak OCR's own output included (all thirty-eight PDFs in its checkouts carry one), so a policy refusing fonts would refuse the text layers it exists to protect. A flaw in the font program is out of this library's reach; the boxed process is the defence.", "refusal": null, "verified_by": [], "protect": { "general": "Upgrade to FreeType 2.14.2.", - "specific": "Until a policy on embedded fonts exists, render in a boxed process; an image-only PDF carries no font." + "specific": "Render in a boxed process; an image-only PDF carries no font." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-23865" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. Moved from B2 to C on 2026-11-02, with the finding above." } diff --git a/docs/advisories/proposed/CVE-2026-50811.json b/docs/advisories/proposed/CVE-2026-50811.json index 9a2c127..b1e4c02 100644 --- a/docs/advisories/proposed/CVE-2026-50811.json +++ b/docs/advisories/proposed/CVE-2026-50811.json @@ -12,18 +12,18 @@ "fixed": null, "reached_by": "open", "trigger": "Rendering a PDF whose embedded variable font makes FreeType call TT_Get_Var_Design with crafted data.", - "bucket": "B2", - "finding": "Reached through an embedded variable font that pdffonts would report; a coarse policy on embedded fonts would keep it from FreeType. Not built.", + "bucket": "C", + "finding": "Reached through an embedded variable font that pdffonts would report; a coarse policy on embedded fonts would keep it from FreeType. No policy is built: every searchable PDF embeds a font, Tetrak OCR's own output included (all thirty-eight PDFs in its checkouts carry one), so a policy refusing fonts would refuse the text layers it exists to protect. A flaw in the font program is out of this library's reach; the boxed process is the defence.", "refusal": null, "verified_by": [], "protect": { "general": "Upgrade FreeType to a version that has the fix; the upstream record names it.", - "specific": "Until a policy on embedded fonts exists, render in a boxed process." + "specific": "Render in a boxed process." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-50811" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. Moved from B2 to C on 2026-11-02, with the finding above." } diff --git a/docs/advisories/proposed/CVE-2026-93312.json b/docs/advisories/proposed/CVE-2026-93312.json index 5529544..3045b96 100644 --- a/docs/advisories/proposed/CVE-2026-93312.json +++ b/docs/advisories/proposed/CVE-2026-93312.json @@ -13,17 +13,23 @@ "reached_by": "open", "trigger": "Rendering a PDF page whose image is a crafted JBIG2 stream.", "bucket": "B2", - "finding": "A JBIG2 stream, which pdfimages -list reports; a coarse policy refusing JBIG2 would keep it from the decoder, at the cost of refusing scanners that write JBIG2. Not built.", - "refusal": null, - "verified_by": [], + "finding": "Reached by rendering a page whose image is a JBIG2 stream. The image's filter is named in its stream dictionary, which cannot be hidden inside a compressed object stream, so a bounded search of the bytes finds /JBIG2Decode and the policy can refuse the codec by name (pdf_image_codecs). The default allows it: scanners and the archives that derive PDFs from scans write JBIG2 (five of the seven PDFs in Tetrak OCR's corpus). pdfimages -list would report the codec too, but it opens a JPX stream with OpenJPEG just to describe it, so the library does not run it.", + "refusal": { + "check": "pdf_image_codecs", + "default": false, + "setting": "Policy(pdf_image_codecs={\"jpeg\", \"jpx\", \"ccitt\"})" + }, + "verified_by": [ + "tests/test_check.py::TestPdf::test_a_jbig2_pdf_under_a_policy_that_refuses_it" + ], "protect": { "general": "Upgrade to poppler 26.08.0.", - "specific": "Until a policy on image stream encodings exists, render in a boxed process." + "specific": "If nothing you handle is JBIG2-coded, say so in the policy: sillybos --pdf-image-codecs jpeg,jpx,ccitt. Otherwise render in a boxed process." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-93312" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. The policy field was named on 2026-11-02." } diff --git a/docs/advisories/proposed/CVE-2026-93313.json b/docs/advisories/proposed/CVE-2026-93313.json index fe3a217..7e5591f 100644 --- a/docs/advisories/proposed/CVE-2026-93313.json +++ b/docs/advisories/proposed/CVE-2026-93313.json @@ -13,17 +13,23 @@ "reached_by": "open", "trigger": "Rendering a PDF page whose JBIG2 stream carries a crafted code table segment.", "bucket": "B2", - "finding": "A JBIG2 stream, which pdfimages -list reports; as CVE-2026-93312. Not built.", - "refusal": null, - "verified_by": [], + "finding": "Reached by rendering a page whose image is a JBIG2 stream. The image's filter is named in its stream dictionary, which cannot be hidden inside a compressed object stream, so a bounded search of the bytes finds /JBIG2Decode and the policy can refuse the codec by name (pdf_image_codecs). The default allows it: scanners and the archives that derive PDFs from scans write JBIG2 (five of the seven PDFs in Tetrak OCR's corpus). pdfimages -list would report the codec too, but it opens a JPX stream with OpenJPEG just to describe it, so the library does not run it.", + "refusal": { + "check": "pdf_image_codecs", + "default": false, + "setting": "Policy(pdf_image_codecs={\"jpeg\", \"jpx\", \"ccitt\"})" + }, + "verified_by": [ + "tests/test_check.py::TestPdf::test_a_jbig2_pdf_under_a_policy_that_refuses_it" + ], "protect": { "general": "Upgrade poppler to a version that has the fix; the upstream record names it.", - "specific": "Until a policy on image stream encodings exists, render in a boxed process." + "specific": "If nothing you handle is JBIG2-coded, say so in the policy: sillybos --pdf-image-codecs jpeg,jpx,ccitt. Otherwise render in a boxed process." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-93313" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. The policy field was named on 2026-11-02." } diff --git a/docs/advisories/proposed/CVE-2026-93314.json b/docs/advisories/proposed/CVE-2026-93314.json index 16bd2da..5004e49 100644 --- a/docs/advisories/proposed/CVE-2026-93314.json +++ b/docs/advisories/proposed/CVE-2026-93314.json @@ -12,18 +12,18 @@ "fixed": null, "reached_by": "open", "trigger": "Rendering a PDF whose embedded TrueType font declares a crafted segCnt in its cmap.", - "bucket": "B2", - "finding": "Reached through an embedded font that pdffonts would report; a coarse policy on embedded fonts would keep it from the font parser, at the cost of searchable PDFs' text layers. Not built.", + "bucket": "C", + "finding": "Reached through an embedded font that pdffonts would report; a coarse policy on embedded fonts would keep it from the font parser, at the cost of searchable PDFs' text layers. No policy is built: every searchable PDF embeds a font, Tetrak OCR's own output included (all thirty-eight PDFs in its checkouts carry one), so a policy refusing fonts would refuse the text layers it exists to protect. A flaw in the font program is out of this library's reach; the boxed process is the defence.", "refusal": null, "verified_by": [], "protect": { "general": "Upgrade poppler to a version that has the fix; the upstream record names it.", - "specific": "Until a policy on embedded fonts exists, render in a boxed process." + "specific": "Render in a boxed process." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-93314" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. Moved from B2 to C on 2026-11-02, with the finding above." } diff --git a/docs/advisories/proposed/CVE-2026-95512.json b/docs/advisories/proposed/CVE-2026-95512.json index f515775..a9ce750 100644 --- a/docs/advisories/proposed/CVE-2026-95512.json +++ b/docs/advisories/proposed/CVE-2026-95512.json @@ -12,18 +12,18 @@ "fixed": null, "reached_by": "open", "trigger": "Rendering a PDF whose embedded CID-keyed font repeats subroutine data across many font dictionaries.", - "bucket": "B2", - "finding": "Reached through an embedded font that pdffonts would report; a coarse policy on embedded fonts would keep it from FreeType. Not built. A time limit on the renderer bounds the cost.", + "bucket": "C", + "finding": "Reached through an embedded font that pdffonts would report; a coarse policy on embedded fonts would keep it from FreeType. A time limit on the renderer bounds the cost. No policy is built: every searchable PDF embeds a font, Tetrak OCR's own output included (all thirty-eight PDFs in its checkouts carry one), so a policy refusing fonts would refuse the text layers it exists to protect. A flaw in the font program is out of this library's reach; the boxed process is the defence.", "refusal": null, "verified_by": [], "protect": { "general": "Upgrade FreeType to a version that has the fix; the upstream record names it.", - "specific": "Until a policy on embedded fonts exists, render in a boxed process with a time limit." + "specific": "Render in a boxed process with a time limit." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2026-95512" ], "triaged": "2026-11-01", "checked": "2026-11-01", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person. Moved from B2 to C on 2026-11-02, with the finding above." } diff --git a/docs/api.md b/docs/api.md index b479fd9..d923184 100644 --- a/docs/api.md +++ b/docs/api.md @@ -46,6 +46,8 @@ chooses from it. ::: sillybos.PDF_FEATURES +::: sillybos.PDF_IMAGE_CODECS + ::: sillybos.PNG_COLOUR_TYPES ::: sillybos.TIFF_COMPRESSIONS diff --git a/src/sillybos/__init__.py b/src/sillybos/__init__.py index a761715..3d58f20 100644 --- a/src/sillybos/__init__.py +++ b/src/sillybos/__init__.py @@ -36,6 +36,7 @@ FORMATS, JPEG_FRAMES, PDF_FEATURES, + PDF_IMAGE_CODECS, PNG_COLOUR_TYPES, STRICT, TIFF_COMPRESSIONS, @@ -54,6 +55,7 @@ "FORMATS", "JPEG_FRAMES", "PDF_FEATURES", + "PDF_IMAGE_CODECS", "PNG_COLOUR_TYPES", "STRICT", "TIFF_COMPRESSIONS", diff --git a/src/sillybos/check.py b/src/sillybos/check.py index 89e9f06..3616aa8 100644 --- a/src/sillybos/check.py +++ b/src/sillybos/check.py @@ -31,6 +31,7 @@ FORMATS, JPEG_FRAMES, PDF_FEATURES, + PDF_IMAGE_CODECS, PNG_COLOUR_TYPES, TIFF_COMPRESSIONS, TIFF_PHOTOMETRICS, @@ -80,6 +81,9 @@ class Facts: features: Which of [sillybos.PDF_FEATURES][] a PDF carries: JavaScript, a form, attached files, a launch action. Empty for an image and for a PDF with none. + codecs: Which of [sillybos.PDF_IMAGE_CODECS][] a PDF's images are + coded with, by the filters named in the file. Empty for an + image and for a PDF whose images use none of them. """ bytes: int @@ -99,6 +103,7 @@ class Facts: tile: tuple[int, int] | None = None subsampling: str | None = None features: tuple[str, ...] = () + codecs: tuple[str, ...] = () @dataclass(frozen=True) @@ -233,6 +238,7 @@ def _facts(path: Path, fmt: str, f: headers.Reader, size: int, policy: Policy) - info.max_side, info.encrypted, features=info.features, + codecs=info.codecs, ) header = headers.READERS[fmt](f, size, policy.max_pages) return Facts( @@ -278,6 +284,14 @@ def _against_limits(facts: Facts, policy: Policy, fmt: str) -> list[str]: allowed = [_FEATURE_WORDS[name] for name in PDF_FEATURES if name in policy.pdf_features] permits = _listed(allowed) if allowed else "none of the features a PDF can carry" reasons.append(f"a PDF with {found}; the policy allows {permits}") + refused_codecs = [name for name in facts.codecs if name not in policy.pdf_image_codecs] + if refused_codecs: + found = _listed([_CODEC_WORDS[name] for name in refused_codecs]) + allowed = [ + _CODEC_WORDS[name] for name in PDF_IMAGE_CODECS if name in policy.pdf_image_codecs + ] + permits = _listed(allowed) if allowed else "none of the image codecs a PDF can carry" + reasons.append(f"a PDF with images coded as {found}; the policy allows {permits}") if facts.coding is not None and facts.coding not in policy.jpeg_frames: allowed = [name for name in JPEG_FRAMES if name in policy.jpeg_frames] article = "an" if facts.coding[0] in "aeiou" else "a" @@ -318,6 +332,7 @@ def _against_limits(facts: Facts, policy: Policy, fmt: str) -> list[str]: return reasons +_CODEC_WORDS = {"jpeg": "JPEG", "jpx": "JPEG 2000", "jbig2": "JBIG2", "ccitt": "CCITT"} _FEATURE_WORDS = { "javascript": "JavaScript", "forms": "a form", diff --git a/src/sillybos/cli.py b/src/sillybos/cli.py index ab7ec2c..75be4ef 100644 --- a/src/sillybos/cli.py +++ b/src/sillybos/cli.py @@ -56,6 +56,8 @@ def _policy(args: argparse.Namespace) -> Policy: changes["tiff_subsamplings"] = frozenset(args.tiff_subsamplings.split(",")) if args.pdf_features: changes["pdf_features"] = frozenset(args.pdf_features.split(",")) + if args.pdf_image_codecs: + changes["pdf_image_codecs"] = frozenset(args.pdf_image_codecs.split(",")) if args.any_name: changes["name_must_match"] = False return dataclasses.replace(base, **changes) if changes else base @@ -151,6 +153,14 @@ def build_parser() -> argparse.ArgumentParser: "javascript,forms,attachments,launch (default: none)" ), ) + parser.add_argument( + "--pdf-image-codecs", + metavar="LIST", + help=( + "comma-separated codecs a PDF's images may be coded with, from " + "jpeg,jpx,jbig2,ccitt (default: all four)" + ), + ) parser.add_argument( "--any-name", action="store_true", diff --git a/src/sillybos/pdf.py b/src/sillybos/pdf.py index 45e4fe4..4cfbf45 100644 --- a/src/sillybos/pdf.py +++ b/src/sillybos/pdf.py @@ -17,6 +17,14 @@ because poppler before 26 reports only document-level scripts and not one attached to an open-document action. +The codec of each image is found the same way, by the name of its filter +(`/JBIG2Decode`, `/JPXDecode`, `/DCTDecode`, `/CCITTFaxDecode`). A stream's +dictionary cannot be hidden inside a compressed object stream, so the name +is in plain bytes unless the filter is given through an indirect reference. +`pdfimages -list` would report the codecs too, but it opens a JPX stream +with OpenJPEG to describe it, which is exactly the decoder's code this +check exists to keep from the file, so it is never run. + `pdfinfo` and `pdfdetach` come with poppler (`brew install poppler`, `apt install poppler-utils`), which anything that renders PDFs in Python already needs. Without them, a PDF cannot be checked, and [PdfInfoMissing][sillybos.pdf.PdfInfoMissing] @@ -46,12 +54,12 @@ def _name_pattern(name: str) -> re.Pattern[bytes]: """A pattern for the PDF name `/name`, however its letters are escaped. A name in a PDF may write any character as `#` and two hex digits, so - `/Launch` may appear as `/L#61unch`. The pattern matches each letter - either way, and requires a delimiter after the name so that `/Launcher` - is not `/Launch`. + `/Launch` may appear as `/L#61unch` and `/JBIG2Decode` as `/JBIG#32Decode`. + The pattern matches each letter and digit either way, and requires a + delimiter after the name so that `/Launcher` is not `/Launch`. """ letters = "".join( - f"(?:{re.escape(c)}|#{ord(c):02x}|#{ord(c):02X})" if c.isalpha() else re.escape(c) + f"(?:{re.escape(c)}|#{ord(c):02x}|#{ord(c):02X})" if c.isalnum() else re.escape(c) for c in name ) return re.compile(rf"/{letters}(?![A-Za-z0-9#])".encode()) @@ -59,6 +67,20 @@ def _name_pattern(name: str) -> re.Pattern[bytes]: _LAUNCH = _name_pattern("Launch") _JAVASCRIPT_NAMES = (_name_pattern("JavaScript"), _name_pattern("JS")) + + +def _any_name(*names: str) -> re.Pattern[bytes]: + """A pattern for any of several PDF names, each however its letters are escaped.""" + return re.compile(b"|".join(_name_pattern(name).pattern for name in names)) + + +_CODEC_NAMES: tuple[tuple[str, re.Pattern[bytes]], ...] = ( + # The abbreviations are the ones an inline image may use. + ("jpeg", _any_name("DCTDecode", "DCT")), + ("jpx", _any_name("JPXDecode")), + ("jbig2", _any_name("JBIG2Decode")), + ("ccitt", _any_name("CCITTFaxDecode", "CCF")), +) _SCAN_CHUNK = 1024 * 1024 _SCAN_OVERLAP = 32 # longer than the longest escaped spelling of the name @@ -90,6 +112,9 @@ class PdfHeader: features: Which of [sillybos.PDF_FEATURES][] the file carries, in that order. Attached files and launch actions are only looked for when the page count is within the limit. + codecs: Which of [sillybos.PDF_IMAGE_CODECS][] the file's images + are coded with, in that order, by the filters named in it. + Looked for in the same pass as the launch action. """ pages: int @@ -99,6 +124,7 @@ class PdfHeader: max_pixels: int | None max_side: int | None features: tuple[str, ...] = () + codecs: tuple[str, ...] = () def _pdfinfo(args: list[str], path: Path, timeout: float) -> str: @@ -155,8 +181,12 @@ def _has_launch_action(path: Path) -> bool: return _names_in(path, _LAUNCH)[0] -def _features(summary: str, path: Path, policy: Policy, *, within_limit: bool) -> tuple[str, ...]: +def _contents( + summary: str, path: Path, policy: Policy, *, within_limit: bool +) -> tuple[tuple[str, ...], tuple[str, ...]]: + """The features the file carries and the codecs its images use, as two tuples.""" found = [] + codecs: list[str] = [] if _JAVASCRIPT.search(summary): found.append("javascript") form = _FORM.search(summary) @@ -167,12 +197,14 @@ def _features(summary: str, path: Path, policy: Policy, *, within_limit: bool) - count = _ATTACHMENTS.search(listing) if count is not None and int(count.group(1)) > 0: found.append("attachments") - scripted, script, launch = _names_in(path, *_JAVASCRIPT_NAMES, _LAUNCH) + hits = _names_in(path, *_JAVASCRIPT_NAMES, _LAUNCH, *(p for _, p in _CODEC_NAMES)) + scripted, script, launch = hits[:3] if (scripted or script) and "javascript" not in found: found.insert(0, "javascript") if launch: found.append("launch") - return tuple(found) + codecs = [name for (name, _), hit in zip(_CODEC_NAMES, hits[3:], strict=True) if hit] + return tuple(found), tuple(codecs) def _pixels(points: str, dpi: int) -> float: @@ -205,8 +237,8 @@ def pdf(path: Path, policy: Policy) -> PdfHeader: width = round(_pixels(first.group(2), policy.render_dpi)) height = round(_pixels(first.group(3), policy.render_dpi)) if pages > policy.max_pages: - features = _features(summary, path, policy, within_limit=False) - return PdfHeader(pages, encrypted, width, height, None, None, features) + features, codecs = _contents(summary, path, policy, within_limit=False) + return PdfHeader(pages, encrypted, width, height, None, None, features, codecs) listing = _pdfinfo(["-f", "1", "-l", str(pages)], path, policy.pdfinfo_timeout) sides = [ (_pixels(w, policy.render_dpi), _pixels(h, policy.render_dpi)) @@ -214,7 +246,7 @@ def pdf(path: Path, policy: Policy) -> PdfHeader: ] if not sides: raise HeaderError("pdfinfo reported no page sizes") - features = _features(summary, path, policy, within_limit=True) + features, codecs = _contents(summary, path, policy, within_limit=True) max_pixels = round(max(w * h for w, h in sides)) max_side = round(max(max(w, h) for w, h in sides)) - return PdfHeader(pages, encrypted, width, height, max_pixels, max_side, features) + return PdfHeader(pages, encrypted, width, height, max_pixels, max_side, features, codecs) diff --git a/src/sillybos/policy.py b/src/sillybos/policy.py index f9f9ae9..048e3c9 100644 --- a/src/sillybos/policy.py +++ b/src/sillybos/policy.py @@ -89,6 +89,16 @@ a launch action that runs a program. A scanned book has none of them, so the default policy refuses them all; a policy names the ones it will pass.""" +PDF_IMAGE_CODECS: tuple[str, ...] = ("jpeg", "jpx", "jbig2", "ccitt") +"""Every codec a PDF's images can be coded with that hands the stream to a +decoder of its own inside poppler, by name: DCT (JPEG), JPX (JPEG 2000, +through OpenJPEG), JBIG2 and CCITT fax. Scanners, and the archives that +derive PDFs from scans, write all four, so the default allows them all; a +policy that knows its source never writes one refuses it by name. Each is +found by its filter's name in the file, not by listing the images: +`pdfimages -list` opens a JPX stream with OpenJPEG to describe it, which is +the decoder's code the check exists to keep from the file.""" + MIB = 1024 * 1024 @@ -184,6 +194,17 @@ class Policy: since no poppler tool reports one, so an action hidden in a compressed stream is not seen; JavaScript is looked for both ways. + pdf_image_codecs: Which of [PDF_IMAGE_CODECS][sillybos.PDF_IMAGE_CODECS] a PDF's + images may be coded with: JPEG, JPEG 2000, JBIG2 and CCITT. + Each hands the stream to a decoder of its own inside poppler, + and the JBIG2 decoder is where several of its flaws have been + (CVE-2025-32365, CVE-2026-93312, CVE-2026-93313). Scanners and + the archives that derive PDFs from scans write all four, so the + default allows them all; refuse one only when you know your + source never writes it. Each is found by its filter's name in + the file, the way a launch action is, so a filter named only + through an indirect reference inside a compressed object + stream is not seen. pdfinfo_timeout: Seconds to give `pdfinfo` before giving up on a PDF, which is then refused. A crafted file can make a parser loop; a limit turns that into one file's failure. @@ -215,6 +236,7 @@ class Policy: ) allow_encrypted_pdf: bool = False pdf_features: frozenset[str] = frozenset() + pdf_image_codecs: frozenset[str] = field(default_factory=lambda: frozenset(PDF_IMAGE_CODECS)) pdfinfo_timeout: float = 30.0 def __post_init__(self) -> None: @@ -261,6 +283,12 @@ def __post_init__(self) -> None: raise ValueError( f"unknown PDF feature(s) {sorted(unknown)}; the features are {', '.join(PDF_FEATURES)}" ) + unknown = set(self.pdf_image_codecs) - set(PDF_IMAGE_CODECS) + if unknown: + raise ValueError( + f"unknown PDF image codec(s) {sorted(unknown)}; " + f"the codecs are {', '.join(PDF_IMAGE_CODECS)}" + ) for name in ( "max_bytes", "max_pixels", diff --git a/tests/corpus.py b/tests/corpus.py index 564a159..481e526 100644 --- a/tests/corpus.py +++ b/tests/corpus.py @@ -322,12 +322,14 @@ def pdf( sizes: list[tuple[float, float]] | None = None, catalog: str = "", objects: list[bytes] | None = None, + page: str = "", ) -> bytes: """A minimal but well-formed PDF: ``pages`` empty pages of the given size, with an xref. - ``catalog`` is appended inside the catalogue dictionary and ``objects`` - are added after the pages, numbered from ``pages + 3``, so a test can - give the document a feature a scan never has (see :func:`pdf_with`). + ``catalog`` is appended inside the catalogue dictionary, ``page`` inside + every page's, and ``objects`` are added after the pages, numbered from + ``pages + 3``, so a test can give the document a feature a scan never + has (see :func:`pdf_with`). """ per_page = sizes or [(width_pts, height_pts)] * pages extra = objects or [] @@ -337,7 +339,7 @@ def pdf( f"<< /Type /Pages /Kids [{kids}] /Count {pages} >>".encode(), ] for w, h in per_page: - parts.append(f"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 {w:g} {h:g}] >>".encode()) + parts.append(f"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 {w:g} {h:g}] {page} >>".encode()) parts.extend(extra) objects = parts out = bytearray(b"%PDF-1.4\n%\xe2\xe3\xcf\xd3\n") @@ -361,6 +363,16 @@ def write(path: Path, data: bytes) -> Path: return path +IMAGE_FILTERS = { + "jpeg": "DCTDecode", + "jpx": "JPXDecode", + "jbig2": "JBIG2Decode", + "escaped-jbig2": "JBIG#32Decode", + "ccitt": "CCITTFaxDecode", +} +"""The PDF filter that :func:`pdf_with` gives an image, by the codec's name.""" + + def pdf_with(feature: str, pages: int = 1) -> bytes: """A one-page PDF carrying one of the features a scanned book never has. @@ -369,8 +381,27 @@ def pdf_with(feature: str, pages: int = 1) -> bytes: ``escaped-launch`` likewise; ``document-javascript`` is a script in the document's name tree, which is what every poppler reports; ``forms`` is an AcroForm with one text field; ``attachments`` is one embedded file. + + ``jpeg``, ``jpx``, ``jbig2`` and ``ccitt`` draw one image coded with that + filter on the first page, its stream sixteen zero bytes that no decoder + is asked to read; ``escaped-jbig2`` is the JBIG2 one with the filter's + name written in ``#xx`` escapes. """ first = pages + 3 + if feature in IMAGE_FILTERS: + data = b"\x00" * 16 + image = ( + "<< /Type /XObject /Subtype /Image /Width 8 /Height 8 /ColorSpace /DeviceGray " + f"/BitsPerComponent 1 /Filter /{IMAGE_FILTERS[feature]} /Length {len(data)} >>\nstream\n" + ) + return pdf( + pages, + page=f"/Resources << /XObject << /Im0 {first} 0 R >> >> /Contents {first + 1} 0 R", + objects=[ + image.encode() + data + b"\nendstream", + b"<< /Length 30 >>\nstream\nq 100 0 0 100 0 0 cm /Im0 Do Q\nendstream", + ], + ) if feature == "document-javascript": return pdf( pages, diff --git a/tests/test_check.py b/tests/test_check.py index b879259..61e3a3a 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -8,7 +8,7 @@ import pytest from PIL import Image -from sillybos import DEFAULT, STRICT, Policy, Refused, check, require +from sillybos import DEFAULT, PDF_IMAGE_CODECS, STRICT, Policy, Refused, check, require from tests import corpus needs_pdfinfo = pytest.mark.skipif(shutil.which("pdfinfo") is None, reason="pdfinfo (poppler)") @@ -360,6 +360,43 @@ def test_strict_is_shorter(self, tmp_path: Path) -> None: def test_a_plain_pdf_carries_no_features(self, tmp_path: Path) -> None: verdict = check(corpus.write(tmp_path / "plain.pdf", corpus.pdf(1))) assert verdict.ok and verdict.facts is not None and verdict.facts.features == () + assert verdict.facts.codecs == () + + @pytest.mark.parametrize( + ("feature", "codec", "words"), + [ + ("jpeg", "jpeg", "JPEG"), + ("jpx", "jpx", "JPEG 2000"), + ("jbig2", "jbig2", "JBIG2"), + ("escaped-jbig2", "jbig2", "JBIG2"), + ("ccitt", "ccitt", "CCITT"), + ], + ) + def test_an_image_codec_passes_by_default_and_is_refused_by_name( + self, tmp_path: Path, feature: str, codec: str, words: str + ) -> None: + path = corpus.write(tmp_path / "scan.pdf", corpus.pdf_with(feature)) + + verdict = check(path) + + assert verdict.ok and verdict.facts is not None and verdict.facts.codecs == (codec,) + assert check(path, STRICT).ok + refused = check(path, Policy(pdf_image_codecs=frozenset(PDF_IMAGE_CODECS) - {codec})) + assert not refused.ok + assert refused.reasons[0].startswith( + f"a PDF with images coded as {words}; the policy allows " + ) + + def test_a_jbig2_pdf_under_a_policy_that_refuses_it(self, tmp_path: Path) -> None: + path = corpus.write(tmp_path / "scan.pdf", corpus.pdf_with("jbig2")) + verdict = check(path, Policy(pdf_image_codecs=frozenset({"jpeg", "jpx", "ccitt"}))) + assert verdict.reasons == ( + "a PDF with images coded as JBIG2; the policy allows JPEG, JPEG 2000 and CCITT", + ) + assert check(path, Policy(pdf_image_codecs=frozenset())).reasons == ( + "a PDF with images coded as JBIG2; " + "the policy allows none of the image codecs a PDF can carry", + ) @pytest.mark.parametrize( ("feature", "found", "words"), @@ -430,6 +467,7 @@ def test_presets(self) -> None: ({"max_png_bit_depth": 12}, "must be 1, 2, 4, 8 or 16"), ({"pdfinfo_timeout": 0}, "must be positive"), ({"pdf_features": frozenset({"macros"})}, "unknown PDF feature"), + ({"pdf_image_codecs": frozenset({"webp"})}, "unknown PDF image codec"), ], ) def test_refuses_an_impossible_policy(self, changes: dict[str, object], reason: str) -> None: diff --git a/tests/test_cli.py b/tests/test_cli.py index f107c42..20d69d0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -105,3 +105,11 @@ def test_pdf_features_can_be_allowed(tmp_path: Path) -> None: assert main([str(scripted)]) == 1 assert main(["--pdf-features", "javascript", str(scripted)]) == 0 assert main(["--pdf-features", "forms", str(scripted)]) == 1 + + +@pytest.mark.skipif(shutil.which("pdfinfo") is None, reason="pdfinfo (poppler)") +def test_pdf_image_codecs_can_be_refused(tmp_path: Path) -> None: + scan = corpus.write(tmp_path / "scan.pdf", corpus.pdf_with("jbig2")) + assert main([str(scan)]) == 0 + assert main(["--pdf-image-codecs", "jpeg,jpx,ccitt", str(scan)]) == 1 + assert main(["--pdf-image-codecs", "jbig2", str(scan)]) == 0 From 24572dff13ccdd517547b3da3fb07ee3351312ce Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Mon, 2 Nov 2026 23:34:33 +0000 Subject: [PATCH 2/2] docs(advisories): promote CVE-2025-9900, now that max_side holds every side Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.1 --- docs/advisories/record.json | 45 ++++++++++++++++++++--- docs/advisories/record/CVE-2025-9900.json | 35 ++++++++++++++++++ 2 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 docs/advisories/record/CVE-2025-9900.json diff --git a/docs/advisories/record.json b/docs/advisories/record.json index b90f749..c17cab3 100644 --- a/docs/advisories/record.json +++ b/docs/advisories/record.json @@ -1,5 +1,5 @@ { - "generated": "2026-11-01", + "generated": "2026-11-02", "buckets": { "A": "Already refused by an existing check", "B": "Preventable from a header field our readers can see", @@ -17,11 +17,11 @@ "other": "some other way; the finding says" }, "counts": { - "records": 22, - "refused_by_default": 15, + "records": 23, + "refused_by_default": 16, "by_bucket": { "A": 5, - "B": 15, + "B": 16, "B2": 0, "C": 0, "D": 0, @@ -31,7 +31,7 @@ "by_library": { "Pillow": 14, "libpng": 5, - "libtiff": 3 + "libtiff": 4 } }, "records": [ @@ -810,6 +810,41 @@ "https://osv.dev/vulnerability/CVE-2025-64720" ] }, + { + "key": "CVE-2025-9900", + "aliases": [], + "library": "libtiff", + "package": "tiff", + "ecosystem": "Debian", + "title": "An abnormally tall TIFF makes libtiff write colour data to an arbitrary address", + "summary": "A flaw was found in Libtiff.", + "published": "2025-09-23", + "severity": 8.8, + "affected": "LibTIFF, as packaged; see the upstream record", + "fixed": null, + "reached_by": "open", + "trigger": "Reading a TIFF whose image height is abnormally large, through libtiff's RGBA image reading.", + "bucket": "B", + "finding": "The height is in the first directory, which sillybos reads. A height large enough to carry the pixel count past max_pixels was already refused; a tall, narrow image within the pixel budget was not, until max_side: every page, frame and tile is now held to it on its longest side (30,000 by default; no scanner writes a side longer than a few tens of thousands of pixels).", + "refusal": { + "check": "max_side", + "default": true, + "setting": "max_side" + }, + "verified_by": [ + "tests/test_check.py::TestHostileFiles::test_a_tall_narrow_tiff" + ], + "protect": { + "general": "Upgrade libtiff to a version that has the fix; the upstream record names it.", + "specific": "Set max_side from your corpus (the longest side of your largest real page, times two or three); sillybos refuses a taller or wider image before libtiff sees it." + }, + "sources": [ + "https://osv.dev/vulnerability/DEBIAN-CVE-2025-9900" + ], + "triaged": "2026-11-02", + "checked": "2026-11-02", + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." + }, { "triaged": "2026-11-01", "checked": "2026-11-01", diff --git a/docs/advisories/record/CVE-2025-9900.json b/docs/advisories/record/CVE-2025-9900.json new file mode 100644 index 0000000..12c77bc --- /dev/null +++ b/docs/advisories/record/CVE-2025-9900.json @@ -0,0 +1,35 @@ +{ + "key": "CVE-2025-9900", + "aliases": [], + "library": "libtiff", + "package": "tiff", + "ecosystem": "Debian", + "title": "An abnormally tall TIFF makes libtiff write colour data to an arbitrary address", + "summary": "A flaw was found in Libtiff.", + "published": "2025-09-23", + "severity": 8.8, + "affected": "LibTIFF, as packaged; see the upstream record", + "fixed": null, + "reached_by": "open", + "trigger": "Reading a TIFF whose image height is abnormally large, through libtiff's RGBA image reading.", + "bucket": "B", + "finding": "The height is in the first directory, which sillybos reads. A height large enough to carry the pixel count past max_pixels was already refused; a tall, narrow image within the pixel budget was not, until max_side: every page, frame and tile is now held to it on its longest side (30,000 by default; no scanner writes a side longer than a few tens of thousands of pixels).", + "refusal": { + "check": "max_side", + "default": true, + "setting": "max_side" + }, + "verified_by": [ + "tests/test_check.py::TestHostileFiles::test_a_tall_narrow_tiff" + ], + "protect": { + "general": "Upgrade libtiff to a version that has the fix; the upstream record names it.", + "specific": "Set max_side from your corpus (the longest side of your largest real page, times two or three); sillybos refuses a taller or wider image before libtiff sees it." + }, + "sources": [ + "https://osv.dev/vulnerability/DEBIAN-CVE-2025-9900" + ], + "triaged": "2026-11-02", + "checked": "2026-11-02", + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; not yet confirmed by a person." +}