From eb34c4626f2c72b8cf08f529ad1c0870a096f067 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Tue, 17 Nov 2026 12:11:28 +0000 Subject: [PATCH 1/3] fix(imaging): stop sending scanned PDFs to triage as JavaScript, with sillybos 6.0.2 sillybos before 6.0.2 took the three bytes /JS anywhere in a PDF for a script, and megabytes of compressed page images spell them by chance. Long scanned PDFs went to the triage queue as "a PDF with JavaScript", and so did ten of the searchable PDFs this package wrote into workspace/processed, when read back in. 6.0.2 counts /JS only beside the name of an action that can carry a script. Raises the floor from >=6 to >=6.0.2, so that an upgrade brings the fix with it, and the lock from 6.0.1 to 6.0.2. All 1,645 scans in this checkout, the Armenian evaluation pages and one book's page frames now pass; the only verdicts that changed are those ten. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.2 --- pyproject.toml | 2 +- tests/ocr/test_input_limits.py | 65 +++++++++++++++++++++++++--------- uv.lock | 8 ++--- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1daed1b..2664b18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ dependencies = [ # TIFF or PDF within our limits (imaging.open_image and check_pdf). Grew # out of this package; 0.x minor releases are additive, a breaking one # becomes 1.0 and stops at the ceiling. - "sillybos>=6,<7", + "sillybos>=6.0.2,<7", "python-dotenv>=1.0", # Writes the searchable PDF. Core rather than an extra because the roadmap # treats that as the flagship catalogue-ready output, and it should work on diff --git a/tests/ocr/test_input_limits.py b/tests/ocr/test_input_limits.py index ddc9f85..fa8ea7b 100644 --- a/tests/ocr/test_input_limits.py +++ b/tests/ocr/test_input_limits.py @@ -26,6 +26,23 @@ def page(width: int = 200, height: int = 300) -> Image.Image: return Image.new("RGB", (width, height), "white") +def pdf_of(objects: list[bytes]) -> bytes: + """A PDF made of *objects*, numbered from 1, the first being the catalogue.""" + out = bytearray(b"%PDF-1.4\n") + offsets = [] + for number, body in enumerate(objects, start=1): + offsets.append(len(out)) + out += f"{number} 0 obj\n".encode() + body + b"\nendobj\n" + xref = len(out) + out += f"xref\n0 {len(objects) + 1}\n".encode() + b"0000000000 65535 f \n" + for position in offsets: + out += f"{position:010d} 00000 n \n".encode() + out += ( + f"trailer\n<< /Size {len(objects) + 1} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n".encode() + ) + return bytes(out) + + class TestFormats: def test_a_supported_scan_opens(self, tmp_path: Path) -> None: path = tmp_path / "postcard.png" @@ -120,27 +137,41 @@ def test_a_file_poppler_cannot_read_is_refused(self, tmp_path: Path) -> None: def test_a_pdf_that_carries_javascript_is_refused(self, tmp_path: Path) -> None: """sillybos 3 refuses the features a scanned book never has; the reason reaches triage.""" path = tmp_path / "scripted.pdf" - objects = [ - b"<< /Type /Catalog /Pages 2 0 R /OpenAction 4 0 R >>", - b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>", - b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] >>", - b"<< /Type /Action /S /JavaScript /JS (app.alert('hello');) >>", - ] - out = bytearray(b"%PDF-1.4\n") - offsets = [] - for number, body in enumerate(objects, start=1): - offsets.append(len(out)) - out += f"{number} 0 obj\n".encode() + body + b"\nendobj\n" - xref = len(out) - out += f"xref\n0 {len(objects) + 1}\n".encode() + b"0000000000 65535 f \n" - for position in offsets: - out += f"{position:010d} 00000 n \n".encode() - out += f"trailer\n<< /Size {len(objects) + 1} /Root 1 0 R >>\nstartxref\n{xref}\n%%EOF\n".encode() - path.write_bytes(bytes(out)) + path.write_bytes( + pdf_of( + [ + b"<< /Type /Catalog /Pages 2 0 R /OpenAction 4 0 R >>", + b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>", + b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] >>", + b"<< /Type /Action /S /JavaScript /JS (app.alert('hello');) >>", + ] + ) + ) with pytest.raises(InputRefusedError, match="a PDF with JavaScript"): check_pdf(path) + def test_a_scan_whose_image_data_spells_a_script_key_is_read(self, tmp_path: Path) -> None: + """sillybos before 6.0.2 took the bytes ``/JS`` in a page image for JavaScript. + + Megabytes of compressed pixels spell those three bytes by chance, so + long scanned PDFs, and the searchable PDFs this package writes, went + to triage as "a PDF with JavaScript". + """ + path = tmp_path / "scan.pdf" + path.write_bytes( + pdf_of( + [ + b"<< /Type /Catalog /Pages 2 0 R >>", + b"<< /Type /Pages /Kids [3 0 R] /Count 1 >>", + b"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] >>", + b"<< /Length 16 >>\nstream\n\x00\x9c\x01\xfe\x00\x10/JS(\x00\x9c\x01\xfe\x00\x10\nendstream", + ] + ) + ) + + assert check_pdf(path) == 1 + def test_a_tiff_whose_tags_contradict_each_other_is_refused(self, tmp_path: Path) -> None: """sillybos 5 refuses a floating-point Predictor on integer samples; the reason reaches triage.""" import struct diff --git a/uv.lock b/uv.lock index 58dc7ac..c5f12b4 100644 --- a/uv.lock +++ b/uv.lock @@ -4826,11 +4826,11 @@ wheels = [ [[package]] name = "sillybos" -version = "6.0.1" +version = "6.0.2" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/d1/20/4ca33faac6fc1cb6201ee0ab1991a6c623176de6e7b50e5f61470ef4a7f7/sillybos-6.0.1.tar.gz", hash = "sha256:c27f74bff8981037865e636fc09ba74b01cf9149c729918b56b0e771dc3d6b4a", size = 672830, upload-time = "2026-11-17T09:34:38.553Z" } +sdist = { url = "https://files.pythonhosted.org/packages/e4/97/a49c5ab7feccd54d3cd92bafa8bdd2ff43d3a1122b72ce8dae906f3d063e/sillybos-6.0.2.tar.gz", hash = "sha256:ec6ccfe857d19784464c965d1a36bdf9e1ad10b1caca96e70bab3c12367667ef", size = 674488, upload-time = "2026-11-17T12:03:29.595Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/59/22/273c3759af98a91c8b804bdedb7abcad4076db2991a359a1f4f2aa0cb5a9/sillybos-6.0.1-py3-none-any.whl", hash = "sha256:3318dc30033bf21e83ae89977dc52d211d4bb55cb15d7e3017ec92ed786c95d7", size = 48665, upload-time = "2026-11-17T09:34:37.029Z" }, + { url = "https://files.pythonhosted.org/packages/19/79/6b6d1ac526bb4cbf2be9b8c16408f86834c7d360c617004781b136a7a6b7/sillybos-6.0.2-py3-none-any.whl", hash = "sha256:c1e673ea008943d678f3b21f10ffdbbb4d6335e9c5146ea41a783964ac62ba1f", size = 49302, upload-time = "2026-11-17T12:03:27.969Z" }, ] [[package]] @@ -5251,7 +5251,7 @@ requires-dist = [ { name = "python-pptx", marker = "extra == 'docs'", specifier = ">=0.6" }, { name = "reportlab", specifier = ">=4.0" }, { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.5" }, - { name = "sillybos", specifier = ">=6,<7" }, + { name = "sillybos", specifier = ">=6.0.2,<7" }, { name = "sphinx", marker = "extra == 'apidocs'", specifier = ">=8.0" }, { name = "sphinx-argparse", marker = "extra == 'apidocs'", specifier = ">=0.6.1" }, { name = "tetrak-easyocr-armenian", marker = "extra == 'armenian'", specifier = ">=0.12" }, From 780fa529697f17231813c73c1afb55025d9f8f38 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Tue, 17 Nov 2026 15:09:51 +0000 Subject: [PATCH 2/3] build(deps): lock sillybos at 6.0.3 6.0.3 reads a PDF name whole wherever a read boundary falls. It changes no verdict for Tetrak's policy, which refuses no image codec: all 1,645 scans Tetrak reads pass as they do on 6.0.2. The floor stays at 6.0.2, the release that stopped the false JavaScript refusals. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.2 --- uv.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uv.lock b/uv.lock index c5f12b4..a67b73a 100644 --- a/uv.lock +++ b/uv.lock @@ -4826,11 +4826,11 @@ wheels = [ [[package]] name = "sillybos" -version = "6.0.2" +version = "6.0.3" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/e4/97/a49c5ab7feccd54d3cd92bafa8bdd2ff43d3a1122b72ce8dae906f3d063e/sillybos-6.0.2.tar.gz", hash = "sha256:ec6ccfe857d19784464c965d1a36bdf9e1ad10b1caca96e70bab3c12367667ef", size = 674488, upload-time = "2026-11-17T12:03:29.595Z" } +sdist = { url = "https://files.pythonhosted.org/packages/28/df/b4895191ab625e825d40821670fe6f59cc9d4286741486a7debd3f6c1c47/sillybos-6.0.3.tar.gz", hash = "sha256:f64d15ba9bfa350b95cd93c841ac091ae2f63efb7f479ac90570e344a8254779", size = 675531, upload-time = "2026-11-17T13:37:30.341Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/19/79/6b6d1ac526bb4cbf2be9b8c16408f86834c7d360c617004781b136a7a6b7/sillybos-6.0.2-py3-none-any.whl", hash = "sha256:c1e673ea008943d678f3b21f10ffdbbb4d6335e9c5146ea41a783964ac62ba1f", size = 49302, upload-time = "2026-11-17T12:03:27.969Z" }, + { url = "https://files.pythonhosted.org/packages/06/cc/05c888ed4958f0a58498792dd569344a61e0372eecae61ce8dc25d4e6a41/sillybos-6.0.3-py3-none-any.whl", hash = "sha256:1c3e1183017704addf601b66b58d77530a17b49af551ffac8f658e62ec26d08d", size = 49565, upload-time = "2026-11-17T13:37:29.11Z" }, ] [[package]] From ef370b55bd70f538e2dfca12b5b75fd5cf6c8768 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Tue, 17 Nov 2026 15:26:03 +0000 Subject: [PATCH 3/3] build(deps): raise the sillybos floor to 6.0.3 The floor now matches the lock, so an upgrade from PyPI gets the same release a checkout does: the false JavaScript refusals fixed in 6.0.2 and the PDF name scan fixed in 6.0.3. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.2 --- pyproject.toml | 2 +- uv.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2664b18..e634224 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ dependencies = [ # TIFF or PDF within our limits (imaging.open_image and check_pdf). Grew # out of this package; 0.x minor releases are additive, a breaking one # becomes 1.0 and stops at the ceiling. - "sillybos>=6.0.2,<7", + "sillybos>=6.0.3,<7", "python-dotenv>=1.0", # Writes the searchable PDF. Core rather than an extra because the roadmap # treats that as the flagship catalogue-ready output, and it should work on diff --git a/uv.lock b/uv.lock index a67b73a..b3fe1ee 100644 --- a/uv.lock +++ b/uv.lock @@ -5251,7 +5251,7 @@ requires-dist = [ { name = "python-pptx", marker = "extra == 'docs'", specifier = ">=0.6" }, { name = "reportlab", specifier = ">=4.0" }, { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.5" }, - { name = "sillybos", specifier = ">=6.0.2,<7" }, + { name = "sillybos", specifier = ">=6.0.3,<7" }, { name = "sphinx", marker = "extra == 'apidocs'", specifier = ">=8.0" }, { name = "sphinx-argparse", marker = "extra == 'apidocs'", specifier = ">=0.6.1" }, { name = "tetrak-easyocr-armenian", marker = "extra == 'armenian'", specifier = ">=0.12" },