Repository navigation
Depend on the crypto extra, and stop blaming the file for our missing library - #3
Merged
Merged
Conversation
… library A PDF encrypted with AES needs the cryptography package to open. This project declared pypdf and not pypdf[crypto], so a plain pip install could not read one. Publishers encrypt with an empty user password routinely: the document opens for anybody and merely records a request not to copy or print it. 15 of 250 gov.uk documents in the 19 September corpus were exactly this. The dependency was half the defect. The other half was what the tool then said. DependencyError landed in the same branch as a half written file, so a sender with a perfectly good document was told it was most likely truncated or damaged and sent to look for a fault that was never there. The tool already had a check written for this shape, encryption_without_a_password, and could not reach it. Separated the two cases. MissingDependency names the package, says the file is not the problem, and gives the command that fixes it. It subclasses UnreadableDocument so a caller that has never heard of it still fails closed rather than treating the run as clean, and it exits 3 rather than reusing 2: exit 2 sends an operator to examine their document, and here the document was never called into question. The honest posture is untouched on every path. Nothing was examined, so nothing is reported, and that is not a clean result. Removed the punctuation dash from what the tool prints. Two sites: the report header, and the collapsed-finding detail shown under --verbose. Checked for the ASCII spaced double hyphen explicitly, which hid five sites in a sibling project because it does not match a search for the em dash. None here. Rule lines and list bullets are typography and stay. Regenerated the README sample from a real run rather than editing it by hand. The old block had been hand wrapped at a width the tool does not use, which is the drift this repository keeps shipping. Also commits the measurement behind the corpus: measure_history.py exactly as it was run, the two corpus builders, and the 850 row manifest with a source URL on every row. The documents themselves stay out; they are other people's copyrighted material and close to a gigabyte of it. ruff excludes scripts/ because a tidied copy is no longer the program that produced the numbers. The README states the four question chain and says plainly that the tool answers only the first two. It does not separate structural history from genuinely replaced page content, and nothing here claims it does. Minor rather than patch: the output format changes, the set of readable files changes, and there is a new exit code. Tests: 100 before, 108 after. The four new corpus tests all fail against origin/main installed as its own pyproject declares. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
before-you-send0.2.1 declareddependencies = ["pypdf>=5.1"]. pypdf needs thecryptographypackage to read a PDF encrypted with AES, and that package was neverpulled in. Publishers encrypt with an empty user password as a matter of routine:
the document opens for anybody and merely records a request not to copy or print it.
15 of 250 gov.uk documents in the 19 September corpus were exactly this shape.
What a stranger got from a plain
pip install before-you-send, reproduced in a cleanvirtualenv against an AES-256 empty-password PDF:
Every word of that diagnosis is false. The same tool, on the same file, with
cryptographyinstalled and nothing else changed, returns a full report at exit 1 withthree findings, one of them
encryption_without_a_password: "The document is marked asrestricted but opens with no password at all." The check written for precisely this
document could not be reached.
The dependency was half of it. The other half is that
DependencyErrorlanded in thesame branch as a half written file, so the tool sent somebody to hunt for a fault in a
document that did not have one, while the real fault sat in our own dependency list.
What changed
1. The dependency.
pypdf[crypto]>=5.1. Verified rather than assumed: thecryptoextra resolves
cryptography>3.0at both ends of the declared range, pypdf 5.1.0 and6.19.0.
2. The error path. A new
MissingDependencysays the tool is short of a package,names it from pypdf's own requirement string rather than guessing, and gives the command
that fixes it. It never says truncated or damaged. It is raised at all three sites that
can produce a
DependencyError: the reader construction, the empty-password decrypt, andthe page walk.
The honest posture survives on every path. It still exits non-zero, it still says
nothing was examined, and it still says that is not a clean result. That was never the
defect. The defect was the diagnosis.
3. Exit code 3, and why. Exit 2 means "this file could not be read", and in a
pipeline it sends an operator to go and look at their document. Here the document is fine
and was never examined, so reusing 2 would keep the same false accusation alive in the
exit status after removing it from the text. 0 and 1 are both unavailable: one claims
clean, the other claims findings, and neither happened. So this case gets a code of its
own. Nothing correct regresses: anything treating non-zero as "do not send" still holds,
and a test for exactly 2 now correctly declines to match.
MissingDependencysubclassesUnreadableDocumentso a caller that only knows the parent still fails closed, and thatsubclassing is asserted in a test rather than left as a property of the source that
somebody might reasonably tidy away.
4. Version 0.3.0, minor not patch. The precedent is that a change to what the tool
prints is a minor bump. Here three things move: the output format (the header line and
the
--verbosecollapse detail), the set of files the tool can read, and the exit codes.A patch bump would understate all three.
5. Dashes. Two sites in printed output, re-derived against
origin/mainrather thantrusting an earlier line number:
report.py(the header, stillBefore You Send — <path>in published 0.2.1) and
findings.py(the collapsed-finding detail, printed under--verbose). The ASCII spaced double hyphen" -- "was searched for explicitly, since itdoes not match a search for the em dash and hid five sites in a sibling project. None
here. One spaced hyphen came out of invented fixture text in
make_examples.py, which isechoed back under
--show-content. Rule lines and list bullets are typography and stay.No dash was touched inside a character class, a compound word or a proper name;
content.pyandmetadata.py, which hold the regexes, are not in this diff at all.6. README samples regenerated from a real run. The old block had been hand wrapped at
a width the tool does not use, so it had already drifted from the real output before this
change touched it. Also corrected: "The only dependency is
pypdf", now false, and theexit code line.
The measurement, committed
scripts/measure_history.pyexactly as it was run, the two corpus builders, anddocs/corpus/history-corpus-2026-09-19.tsv, 850 rows carrying source, filename, size,SHA-256 and a URL on every row. The PDFs themselves stay out: other people's
copyrighted material, and about a gigabyte of it. ruff excludes
scripts/, because atidied copy is no longer the program that produced the numbers, and the
obj_dictdocstring recording a real bug in the measuring code is kept for the same reason.
The new README subsection is deliberately separate from the 931 document material above
it, which is about false positive rates over a different corpus collected on a different
day.
docs/corpus-manifest.mdopened by claiming it covered every number in thatsection, which this PR made untrue, so it now names the exception.
It states the four question chain and stops there. The README says plainly that the
tool answers the first two questions only, and that it does not separate structural
history from genuinely replaced page content. That distinction lives in
measure_history.py, a second implementation that imports nothing from this package.Verification
Baseline
origin/main, installed exactly as its own pyproject declares: 100 passed.This branch: 108 passed,
ruff check .clean.The four new corpus tests, run against
origin/mainsource in the shipped condition:The two errors are the point, not noise: pre-fix, the declared environment cannot even
construct the AES-256 file it is being asked to read.
The fixture is generated, never committed, in keeping with the repository's rule that no
PDF enters it. It is the one fixture not assembled from literal bytes, and it cannot be:
hand-writing an AES-256 file would mean implementing the cipher in
conftest.py.Zero punctuation dashes, across both examples and the AES file, over all ten
documented format and threshold options plus
--help,--versionand both refusalpaths, 564 lines of real captured output:
Clean virtualenv, plain
pip install .from this branch, nothing else installed:Both refusal paths confirmed unchanged: a truncated PDF still reports "most likely
truncated or damaged" at exit 2, and a non-PDF still reports "does not begin with a PDF
header" at exit 2.
🤖 Generated with Claude Code