From a05a7198d2c68ae17256e00dd0cd5245879a80c6 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Tue, 3 Nov 2026 17:04:44 +0000 Subject: [PATCH] feat!: refuse a TIFF whose tags contradict each other by default A ColorMap with the wrong number of entries for the bit depth (CVE-2026-112896) or a floating-point Predictor on integer samples (CVE-2026-112396) is malformed, by design or by accident, and no scanner writes either; both exist to reach an encoder that trusts the tag. 4.2.0 reported them and left the default permissive. Now the default refuses them, under DEFAULT and STRICT alike, and a source known to write such files can allow them. BREAKING CHANGE: allow_inconsistent_tiff_tags now defaults to False, so a TIFF with a contradicting ColorMap or Predictor that passed under 4.2.0 is refused. The command-line flag --no-inconsistent-tiff-tags is replaced by --inconsistent-tiff-tags, which allows them. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.1 --- README.md | 2 +- docs/advisories/record.json | 22 ++++++++++----------- docs/advisories/record/CVE-2026-112396.json | 10 +++++----- docs/advisories/record/CVE-2026-112896.json | 10 +++++----- src/sillybos/cli.py | 10 +++++----- src/sillybos/policy.py | 8 ++++---- tests/test_check.py | 10 ++++------ tests/test_cli.py | 6 +++--- 8 files changed, 38 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 62773fc..aac991d 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ check(path, Policy(formats={"tiff", "pdf"}, max_pages=50)) | `tiff_compressions` | none, ccitt, lzw, jpeg, deflate, packbits | the same | How a TIFF may be compressed, by name. The other codecs in libtiff are where most of its flaws have been found (PixarLog most recently, CVE-2026-12912), and a scan never needs them. A code the library does not know is refused whatever the policy says, and every frame must use the same scheme | | `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) | | `tiff_tags` | standard, metadata, private | the same | Which kinds of tag a TIFF's directories may hold. Standard is the TIFF 6.0 set; metadata the registered blocks (XMP, IPTC, Photoshop, Exif, ICC, GPS, GeoTIFF); private everything else, the vendor and DNG tags a scan never carries. A read is not harmed by a private tag, so the default allows all three; a program that saves a file back as TIFF with its tag table carries every tag into libtiff's encoder, where a crafted one copied process memory into the output (CVE-2026-112902), and should allow standard and metadata only | -| `allow_inconsistent_tiff_tags` | yes | yes | Pass a TIFF whose tags contradict each other: a ColorMap of the wrong size for the bit depth (CVE-2026-112896), a floating-point Predictor on integer samples (CVE-2026-112396). No scanner writes either; both reach an encoder that trusts the tag. Allowed by default because refusing a file that passed before is breaking; a policy for files from outside should refuse | +| `allow_inconsistent_tiff_tags` | no | no | Pass a TIFF whose tags contradict each other: a ColorMap of the wrong size for the bit depth (CVE-2026-112896), a floating-point Predictor on integer samples (CVE-2026-112396). No scanner writes either; both reach an encoder that trusts the tag, so the default refuses them, malformed by design or by accident. Allow only for a source known to write such files | | `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 | diff --git a/docs/advisories/record.json b/docs/advisories/record.json index 4cec002..55d08c5 100644 --- a/docs/advisories/record.json +++ b/docs/advisories/record.json @@ -18,7 +18,7 @@ }, "counts": { "records": 123, - "refused_by_default": 44, + "refused_by_default": 46, "by_bucket": { "A": 39, "B": 19, @@ -1275,18 +1275,18 @@ "reached_by": "save", "trigger": "Opening a 16-bit palette TIFF with a 768-entry ColorMap and saving it back as TIFF with its metadata.", "bucket": "B", - "finding": "The ColorMap rides from the opened file's tag table into a save that keeps its metadata. The tag is in the directory the reader walks, and its 768 entries disagree with 16-bit samples, which need 196,608: the reader reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default allows it, because refusing a file that passed before is breaking, so the setting is what closes this.", + "finding": "The ColorMap rides from the opened file's tag table into a save that keeps its metadata. The tag is in the directory the reader walks, and its 768 entries disagree with 16-bit samples, which need 196,608: the reader reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default refuses it since 5.0.0; before that the setting had to be chosen.", "refusal": { "check": "allow_inconsistent_tiff_tags", - "default": false, - "setting": "Policy(allow_inconsistent_tiff_tags=False)" + "default": true, + "setting": "allow_inconsistent_tiff_tags" }, "verified_by": [ "tests/test_check.py::TestHostileFiles::test_a_tiff_whose_colormap_does_not_fit_its_depth" ], "protect": { "general": "Upgrade to Pillow 12.3.0.", - "specific": "Refuse inconsistent TIFF tags (allow_inconsistent_tiff_tags off) for files from outside; upgrade to Pillow 12.3.0." + "specific": "Keep allow_inconsistent_tiff_tags off, as it is by default; upgrade to Pillow 12.3.0." }, "sources": [ "https://osv.dev/vulnerability/GHSA-pchr-8j38-3x4p", @@ -1294,7 +1294,7 @@ ], "triaged": "2026-11-03", "checked": "2026-11-03", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0)." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0). Refused by default from 5.0.0 (3 November 2026)." }, { "key": "CVE-2026-112405", @@ -1414,18 +1414,18 @@ "reached_by": "save", "trigger": "Image.save(format=\"TIFF\") to an in-memory buffer with a tag libtiff rejects.", "bucket": "B", - "finding": "The rejected tag, a floating-point Predictor on integer samples in the report's example, rides into the save when the program keeps the opened file's tag table. The reader reads the Predictor and the SampleFormat and reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default allows it, because refusing a file that passed before is breaking, so the setting is what closes this.", + "finding": "The rejected tag, a floating-point Predictor on integer samples in the report's example, rides into the save when the program keeps the opened file's tag table. The reader reads the Predictor and the SampleFormat and reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default refuses it since 5.0.0; before that the setting had to be chosen.", "refusal": { "check": "allow_inconsistent_tiff_tags", - "default": false, - "setting": "Policy(allow_inconsistent_tiff_tags=False)" + "default": true, + "setting": "allow_inconsistent_tiff_tags" }, "verified_by": [ "tests/test_check.py::TestHostileFiles::test_a_tiff_with_a_floating_point_predictor_on_integer_samples" ], "protect": { "general": "Upgrade to Pillow 12.3.0.", - "specific": "Refuse inconsistent TIFF tags (allow_inconsistent_tiff_tags off) for files from outside, and save to a file rather than memory; upgrade to Pillow 12.3.0." + "specific": "Keep allow_inconsistent_tiff_tags off, as it is by default, and save to a file rather than memory; upgrade to Pillow 12.3.0." }, "sources": [ "https://osv.dev/vulnerability/GHSA-4rr5-89j8-mwwm", @@ -1433,7 +1433,7 @@ ], "triaged": "2026-11-03", "checked": "2026-11-03", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0)." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0). Refused by default from 5.0.0 (3 November 2026)." }, { "key": "CVE-2026-112394", diff --git a/docs/advisories/record/CVE-2026-112396.json b/docs/advisories/record/CVE-2026-112396.json index e995e29..d39a696 100644 --- a/docs/advisories/record/CVE-2026-112396.json +++ b/docs/advisories/record/CVE-2026-112396.json @@ -13,18 +13,18 @@ "reached_by": "save", "trigger": "Image.save(format=\"TIFF\") to an in-memory buffer with a tag libtiff rejects.", "bucket": "B", - "finding": "The rejected tag, a floating-point Predictor on integer samples in the report's example, rides into the save when the program keeps the opened file's tag table. The reader reads the Predictor and the SampleFormat and reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default allows it, because refusing a file that passed before is breaking, so the setting is what closes this.", + "finding": "The rejected tag, a floating-point Predictor on integer samples in the report's example, rides into the save when the program keeps the opened file's tag table. The reader reads the Predictor and the SampleFormat and reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default refuses it since 5.0.0; before that the setting had to be chosen.", "refusal": { "check": "allow_inconsistent_tiff_tags", - "default": false, - "setting": "Policy(allow_inconsistent_tiff_tags=False)" + "default": true, + "setting": "allow_inconsistent_tiff_tags" }, "verified_by": [ "tests/test_check.py::TestHostileFiles::test_a_tiff_with_a_floating_point_predictor_on_integer_samples" ], "protect": { "general": "Upgrade to Pillow 12.3.0.", - "specific": "Refuse inconsistent TIFF tags (allow_inconsistent_tiff_tags off) for files from outside, and save to a file rather than memory; upgrade to Pillow 12.3.0." + "specific": "Keep allow_inconsistent_tiff_tags off, as it is by default, and save to a file rather than memory; upgrade to Pillow 12.3.0." }, "sources": [ "https://osv.dev/vulnerability/GHSA-4rr5-89j8-mwwm", @@ -32,5 +32,5 @@ ], "triaged": "2026-11-03", "checked": "2026-11-03", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0)." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0). Refused by default from 5.0.0 (3 November 2026)." } diff --git a/docs/advisories/record/CVE-2026-112896.json b/docs/advisories/record/CVE-2026-112896.json index cc37bc7..427cfa5 100644 --- a/docs/advisories/record/CVE-2026-112896.json +++ b/docs/advisories/record/CVE-2026-112896.json @@ -13,18 +13,18 @@ "reached_by": "save", "trigger": "Opening a 16-bit palette TIFF with a 768-entry ColorMap and saving it back as TIFF with its metadata.", "bucket": "B", - "finding": "The ColorMap rides from the opened file's tag table into a save that keeps its metadata. The tag is in the directory the reader walks, and its 768 entries disagree with 16-bit samples, which need 196,608: the reader reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default allows it, because refusing a file that passed before is breaking, so the setting is what closes this.", + "finding": "The ColorMap rides from the opened file's tag table into a save that keeps its metadata. The tag is in the directory the reader walks, and its 768 entries disagree with 16-bit samples, which need 196,608: the reader reports the contradiction, and a policy that refuses inconsistent tags refuses the file before Pillow sees it (allow_inconsistent_tiff_tags). The default refuses it since 5.0.0; before that the setting had to be chosen.", "refusal": { "check": "allow_inconsistent_tiff_tags", - "default": false, - "setting": "Policy(allow_inconsistent_tiff_tags=False)" + "default": true, + "setting": "allow_inconsistent_tiff_tags" }, "verified_by": [ "tests/test_check.py::TestHostileFiles::test_a_tiff_whose_colormap_does_not_fit_its_depth" ], "protect": { "general": "Upgrade to Pillow 12.3.0.", - "specific": "Refuse inconsistent TIFF tags (allow_inconsistent_tiff_tags off) for files from outside; upgrade to Pillow 12.3.0." + "specific": "Keep allow_inconsistent_tiff_tags off, as it is by default; upgrade to Pillow 12.3.0." }, "sources": [ "https://osv.dev/vulnerability/GHSA-pchr-8j38-3x4p", @@ -32,5 +32,5 @@ ], "triaged": "2026-11-03", "checked": "2026-11-03", - "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0)." + "notes": "Proposed from the advisory's text on 2026-11-01, as part of folding the backfill into the record; confirmed by a person on 2026-11-03. Re-read on 2026-11-03 against the question of what rides from an opened file into a save: the file is the input. Bucket and finding confirmed by a person on 2026-11-03; waits for the policy on a TIFF's tags and its test before it can be promoted. The policy was built on 2026-11-03 (sillybos 4.2.0). Refused by default from 5.0.0 (3 November 2026)." } diff --git a/src/sillybos/cli.py b/src/sillybos/cli.py index 515e891..1677155 100644 --- a/src/sillybos/cli.py +++ b/src/sillybos/cli.py @@ -56,8 +56,8 @@ def _policy(args: argparse.Namespace) -> Policy: changes["tiff_subsamplings"] = frozenset(args.tiff_subsamplings.split(",")) if args.tiff_tags: changes["tiff_tags"] = frozenset(args.tiff_tags.split(",")) - if args.no_inconsistent_tiff_tags: - changes["allow_inconsistent_tiff_tags"] = False + if args.inconsistent_tiff_tags: + changes["allow_inconsistent_tiff_tags"] = True if args.pdf_features: changes["pdf_features"] = frozenset(args.pdf_features.split(",")) if args.pdf_image_codecs: @@ -158,10 +158,10 @@ def build_parser() -> argparse.ArgumentParser: ), ) parser.add_argument( - "--no-inconsistent-tiff-tags", + "--inconsistent-tiff-tags", action="store_true", - help="refuse a TIFF whose tags contradict each other (a ColorMap of the wrong size, " - "a floating-point Predictor on integer samples)", + help="do not refuse a TIFF whose tags contradict each other (a ColorMap of the wrong " + "size, a floating-point Predictor on integer samples)", ) parser.add_argument( "--pdf-features", diff --git a/src/sillybos/policy.py b/src/sillybos/policy.py index c1e8877..347ba1f 100644 --- a/src/sillybos/policy.py +++ b/src/sillybos/policy.py @@ -205,9 +205,9 @@ class Policy: CVE-2026-112896), or a floating-point Predictor on integer samples (CVE-2026-112396). No scanner writes either; both are what a crafted file carries to reach an encoder that trusts - the tag. The default allows them, because refusing a file - that passed before is a breaking change; a policy for files - from outside should not. + the tag, so the default refuses them, malformed by design or + by accident. A policy for a source known to write such files + can allow them. allow_encrypted_pdf: Pass a PDF that `pdfinfo` reports as encrypted. A scanned book never is, so the default refuses. pdf_features: Which of [PDF_FEATURES][sillybos.PDF_FEATURES] a PDF may carry: @@ -261,7 +261,7 @@ class Policy: default_factory=lambda: frozenset({"none", "ccitt", "lzw", "jpeg", "deflate", "packbits"}) ) tiff_tags: frozenset[str] = field(default_factory=lambda: frozenset(TIFF_TAGS)) - allow_inconsistent_tiff_tags: bool = True + allow_inconsistent_tiff_tags: bool = False allow_encrypted_pdf: bool = False pdf_features: frozenset[str] = frozenset() pdf_image_codecs: frozenset[str] = field(default_factory=lambda: frozenset(PDF_IMAGE_CODECS)) diff --git a/tests/test_check.py b/tests/test_check.py index fdde1af..ea16ee1 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -218,12 +218,11 @@ def test_a_tiff_whose_colormap_does_not_fit_its_depth(self, tmp_path: Path) -> N # in Pillow's encoder when the file is saved back with its metadata. data = corpus.tiff([(10, 10)], layout=(1, 1, 16), tags=[(320, 3, b"\x00" * 1536)]) path = corpus.write(tmp_path / "scan.tif", data) - assert check(path).ok - verdict = check(path, Policy(allow_inconsistent_tiff_tags=False)) - assert verdict.reasons == ( + assert check(path).reasons == ( "a TIFF whose tags contradict each other: frame 1 has a ColorMap of 768 entries " "for 16-bit samples, which need 196,608", ) + assert check(path, Policy(allow_inconsistent_tiff_tags=True)).ok def test_a_tiff_with_a_floating_point_predictor_on_integer_samples( self, tmp_path: Path @@ -232,12 +231,11 @@ def test_a_tiff_with_a_floating_point_predictor_on_integer_samples( # then wrote into a freed buffer when encoding to memory. data = corpus.tiff([(10, 10)], compression=5, tags=[(317, 3, b"\x03\x00")]) path = corpus.write(tmp_path / "scan.tif", data) - assert check(path).ok - verdict = check(path, Policy(allow_inconsistent_tiff_tags=False)) - assert verdict.reasons == ( + assert check(path).reasons == ( "a TIFF whose tags contradict each other: frame 1 has a floating-point Predictor " "on integer samples", ) + assert check(path, Policy(allow_inconsistent_tiff_tags=True)).ok def test_a_cielab_tiff(self, tmp_path: Path) -> None: path = corpus.write(tmp_path / "scan.tif", corpus.tiff([(10, 10)], layout=(8, 3, 8))) diff --git a/tests/test_cli.py b/tests/test_cli.py index b31b47e..1f26276 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -115,11 +115,11 @@ def test_tiff_tags_can_be_refused(tmp_path: Path) -> None: assert main(["--tiff-tags", "private", str(scan)]) == 0 -def test_inconsistent_tiff_tags_can_be_refused(tmp_path: Path) -> None: +def test_inconsistent_tiff_tags_are_refused_unless_allowed(tmp_path: Path) -> None: data = corpus.tiff([(10, 10)], compression=5, tags=[(317, 3, b"\x03\x00")]) scan = corpus.write(tmp_path / "scan.tif", data) - assert main([str(scan)]) == 0 - assert main(["--no-inconsistent-tiff-tags", str(scan)]) == 1 + assert main([str(scan)]) == 1 + assert main(["--inconsistent-tiff-tags", str(scan)]) == 0 def test_pdf_image_codecs_can_be_refused(tmp_path: Path) -> None: