Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/ocr/test_input_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading