diff --git a/docs/installation.md b/docs/installation.md index d75cd3d..028df27 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -15,7 +15,8 @@ the import package is `tetrak_ocr`. A plain install gives you Tesseract (via `pytesseract`), image handling, PDF rasterisation, the searchable-PDF writer, and the check that every scan passes before any of them opens it ([sillybos](https://github.com/scattercode/sillybos): the file really is a -JPEG, PNG, TIFF or PDF, within size and page limits; anything else goes to +JPEG, PNG, TIFF or PDF, within size and page limits, with nothing in its +header or its PDF features that a scan never has; anything else goes to triage with the reason): enough to process a folder of scans offline. Most people want more than that. The install we recommend adds quality diff --git a/pyproject.toml b/pyproject.toml index 25e8faf..8093021 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>=0.1,<1", + "sillybos>=3,<4", "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 87f12c6..8b27a72 100644 --- a/tests/ocr/test_input_limits.py +++ b/tests/ocr/test_input_limits.py @@ -106,6 +106,30 @@ def test_a_file_poppler_cannot_read_is_refused(self, tmp_path: Path) -> None: with pytest.raises(InputRefusedError, match="unknown format"): check_pdf(path) + 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)) + + with pytest.raises(InputRefusedError, match="a PDF with JavaScript"): + check_pdf(path) + class TestPageSize: def test_pillows_one_dpi_for_no_resolution_is_not_believed(self) -> None: