Structure-aware PDF mutation with oracles.
docmutant changes PDF files at the level of their structure (content-stream operators, paths, glyphs, images, fonts) and checks every change against an oracle: a test that says whether a bug shows. One engine serves three modes:
| Mode | Starts from | Goal | The oracle must |
|---|---|---|---|
| reduce / sanitize | a document that shows a bug | remove and replace content until no original expression is left | keep firing |
| fuzz | seed documents | mutate until a new failure appears | start firing |
| metamorphic | any document | apply a change that should not matter, such as a width-preserving glyph swap | stay silent |
Typical oracles: the parser crashes, rendering hangs, the render differs from a second engine (for example pypdfium2), or the extracted text cells differ.
Every output file gets a provenance manifest that records its source, the mutations applied, the oracle results, and the terms under which the file may be shared.
Parser and renderer bugs are often found on documents that cannot be shared: manuals, reports, customer files. Maintainers need a real document that shows the bug, and they need a license that allows it to go into a regression corpus. docmutant aims to turn such a document into a small file that still shows the bug, keeps none of the original expression, and says so in a reviewable record.
The same mutations serve testing and training data. A width-preserving glyph swap keeps every word box where it was, so a layout model or a segmentation step can be checked, or trained, on the same geometry with different text, and the labels stay exact.
Pre-alpha. Built so far:
- the manifest model, with its policy checks and a validator;
- a first reduce/sanitize mode for rendering bugs, with crash, hang and error oracles that run docling-parse;
- an anonymize mode that changes every word and every hidden layer of a document.
Anonymize fits a new word into each word's box. It uses real words from a bundled
vocabulary where one fits, and otherwise invented words or letter swaps. Every line
keeps its box to within a set tolerance. Under the privacy profile it also:
- turns text drawn as outlines into new text;
- makes logos, icons and machine-readable codes flat blocks;
- covers images with flat colour;
- replaces displayed formulas, and words of math it cannot change, with blocks that have a pattern of their own;
- replaces each font program with a freely licensed substitute: one with the same
widths where there is one (Liberation, Carlito, Caladea, and Latin Modern for
TeX's fonts, from
fonts-lmodernor TeX Live), or else a Liberation font of the same kind.
It writes nothing unless the saved file passes its checks. Those include word
geometry and coverage, what pdfium still reads, what Tesseract reads in the
rendered pages, and the pixel difference from the source outside the parts the run
changed. The privacy profile needs Tesseract
on the path. --reader doctr adds docTR as a second
reader (pip install python-doctr, which brings torch): each reader must find no
source word, and none of the words it reads in the source is used as a new one.
Known limits, from runs on real documents:
- A glyph whose font gives no text draws nothing in the substitute font, and the
checks then stop the run. This covers composite fonts without
/ToUnicodeand glyph names that say nothing, such as MathType'sH20850. Text is read from/ToUnicode, from the encoding, and from the encoding built into a Type1 or CFF font program, with TeX's glyph names. - Each check stops a run rather than let a file through. A file can therefore stop on a page that would have passed with a little more room.
See docs/DESIGN.md for the design and the roadmap.
$ docmutant reduce manual.pdf --page 7 --out p7.pdf --oracle crash \
--target-python /path/to/buggy/.venv/bin/python \
--silent-python /path/to/fixed/.venv/bin/python --scale 3.0
$ docmutant attest p7.pdf.docmutant.json --reviewer "A. Reviewer"
$ docmutant validate --check-file p7.pdf.docmutant.json
$ docmutant anonymize report.pdf --out clean.pdf --profile privacy
$ docmutant schema # print the manifest JSON SchemaThe manifest is a sidecar file named <file>.docmutant.json, next to the PDF.
(It does not use .pdf.json, which some corpora use for parser output.)
Each file has a tier:
real: an unchanged real document. It must be byte-identical to its source, and the source must be redistributable.derived: a real document changed by docmutant. The manifest lists the mutations and the tool version and seed, so that the file can be regenerated.synthetic: built by docmutant without a source document.
A file derived from a source that may not be redistributed must also carry
automatic evidence (what remains from the source, similarity measurements),
a signed attestation by a named reviewer, and a takedown_contact. Font
programs without a free license must be replaced or removed. The validator
refuses manifests that break these rules. See
CORPUS-LICENSES.md and
docs/ATTESTATION.md.
The docmutant code is under the MIT License. Its bundled vocabulary is a modified version of SCOWL, under the notice in src/docmutant/data/vocabulary-copyright.txt.
Documents produced with docmutant carry their own license, recorded per file in the manifest. CORPUS-LICENSES.md explains the policy. Nothing in this repository is legal advice.
- pdf-mangler (Curtis, DocEng 2022, MPL-2.0) anonymizes PDFs for bug reports. It strips metadata, replaces text at random, jitters vector paths and blurs images. docmutant differs in that it checks each change against an oracle, keeps glyph widths and exact trigger geometry, replaces font programs, and records provenance.
- GTR (Herfert, Patra and Pradel, ASE 2017) reduces tree-structured inputs, including PDF, with delta debugging.
- Structure-aware PDF fuzzers (for example IUST-DeepFuzz and FuzzInMem) target crashes and code coverage, not render or text differences.
- Document-image augmentation and robustness work (Augraphy, RoDLA, SynthDoG, Genalog) changes rendered images, not the PDF structure.
Issues and pull requests are welcome. Please sign off your commits
(git commit -s, Developer Certificate of Origin).
If you hold rights in a document from which a file here was derived and you
object to it, open an issue titled Takedown: <file name>. We remove the file
first and discuss afterwards.