From 06ad09252baa7361d47f71797cdff21ce1ae0a34 Mon Sep 17 00:00:00 2001 From: Andrew Tierney Date: Mon, 16 Nov 2026 11:03:01 +1100 Subject: [PATCH 1/2] Validate the output with independent readers and the input with fuzzing and corpora A writer that only reads its own output back cannot see the mistakes it shares with itself. validation.yml now puts the example output and a validation corpus (written by tools/SharpCorePDF.Validation, with a manifest of the text, passwords, permissions, revisions and signature coverage each document must have) through qpdf, pypdf, pdfminer.six, MuPDF, pdf.js, fontTools, OTS, PDFium and pyHanko, checks the incremental-update invariants, and replays the fuzz seeds and four hostile documents. robustness.yml runs libFuzzer over the parser and the DCT, CCITT, LZW, Flate and RunLength decoders, reads the veraPDF and pdf.js corpora one process per file, and judges the PDF/A writer with veraPDF over the veraPDF corpus. compliance.yml cross-validates PDF/A-4. The checks found defects that are not fixed here. Each is pinned by a skipped test (PdfSignatureAttackTests, PdfIncrementalInvariantTests) or a strict --known-defect flag that fails the run once the defect is fixed, and docs/validation.md lists them with their evidence. No shipped package changes. The constitution's statement that no Python validator runs in CI is corrected as a proposed PATCH amendment (2.0.1) for the maintainer to ratify. Local AI assistant state (.claude/, CLAUDE.local.md) is ignored. --- .config/dotnet-tools.json | 7 + .github/workflows/compliance.yml | 6 +- .github/workflows/robustness.yml | 282 +++++++++++++++ .github/workflows/validation.yml | 232 ++++++++++++ .gitignore | 4 + .specify/memory/constitution.md | 18 +- CHANGELOG.md | 28 ++ CONTRIBUTING.md | 6 +- README.md | 7 + SharpCorePDF.slnx | 4 +- docs/README.md | 2 + docs/tools/corpus-robustness.py | 207 +++++++++++ docs/tools/render-compare.py | 158 ++++++++ docs/tools/validate-arlington.py | 149 ++++++++ docs/tools/validate-encryption-pdfjs.mjs | 95 +++++ docs/tools/validate-encryption.py | 164 +++++++++ docs/tools/validate-fonts.py | 263 ++++++++++++++ docs/tools/validate-incremental.py | 145 ++++++++ docs/tools/validate-pdf.py | 30 +- docs/tools/validate-pdfa-cross.py | 11 +- docs/tools/validate-preflight-corpus.py | 148 ++++++++ docs/tools/validate-signatures.py | 77 ++++ docs/tools/validate-text.py | 147 ++++++++ docs/tools/validation-requirements.txt | 20 ++ docs/validation.md | 139 +++++++ .../PdfIncrementalInvariantTests.cs | 142 ++++++++ .../PdfSignatureAttackTests.cs | 218 +++++++++++ tools/SharpCorePDF.Validation/CorpusWriter.cs | 338 ++++++++++++++++++ tools/SharpCorePDF.Validation/FuzzTargets.cs | 254 +++++++++++++ tools/SharpCorePDF.Validation/Probe.cs | 251 +++++++++++++ tools/SharpCorePDF.Validation/Program.cs | 138 +++++++ .../SharpCorePDF.Validation.csproj | 52 +++ 32 files changed, 3730 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/robustness.yml create mode 100644 .github/workflows/validation.yml create mode 100644 docs/tools/corpus-robustness.py create mode 100644 docs/tools/render-compare.py create mode 100644 docs/tools/validate-arlington.py create mode 100644 docs/tools/validate-encryption-pdfjs.mjs create mode 100644 docs/tools/validate-encryption.py create mode 100644 docs/tools/validate-fonts.py create mode 100644 docs/tools/validate-incremental.py create mode 100644 docs/tools/validate-preflight-corpus.py create mode 100644 docs/tools/validate-text.py create mode 100644 docs/tools/validation-requirements.txt create mode 100644 docs/validation.md create mode 100644 tests/SharpCorePDF.Tests/PdfIncrementalInvariantTests.cs create mode 100644 tests/SharpCorePDF.Tests/PdfSignatureAttackTests.cs create mode 100644 tools/SharpCorePDF.Validation/CorpusWriter.cs create mode 100644 tools/SharpCorePDF.Validation/FuzzTargets.cs create mode 100644 tools/SharpCorePDF.Validation/Probe.cs create mode 100644 tools/SharpCorePDF.Validation/Program.cs create mode 100644 tools/SharpCorePDF.Validation/SharpCorePDF.Validation.csproj diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 5ccda36..eee80fa 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -8,6 +8,13 @@ "dotnet-stryker" ], "rollForward": false + }, + "sharpfuzz.commandline": { + "version": "2.3.0", + "commands": [ + "sharpfuzz" + ], + "rollForward": false } } } \ No newline at end of file diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml index 2b323f5..2f8af7e 100644 --- a/.github/workflows/compliance.yml +++ b/.github/workflows/compliance.yml @@ -214,7 +214,9 @@ jobs: # The same documents, read by two more implementations. --strict-tools makes a missing tool a failure # rather than a note, because a green run here is supposed to mean that all three agreed. PDFBox 3.0.8 - # and Ghostscript have no PDF/A-4 mode, so veraPDF is the only reading of that profile. + # and Ghostscript have no PDF/A-4 mode, so veraPDF stays the only verdict on that profile; PDFBox still + # parses the PDF 2.0 file and Ghostscript still rewrites it (as part 2), which is the reader test the + # other profiles get too. - name: Cross-validate with a second and a third implementation env: VERAPDF_HOME: ${{ env.VERAPDF_INSTALL }} @@ -223,7 +225,7 @@ jobs: output="$RUNNER_TEMP/SharpCorePDF.Examples/output" jar="$HOME/.cache/pdfbox/preflight-app-${PDFBOX_PREFLIGHT_VERSION}.jar" - for profile in 1b 2b 2u 3b 3u; do + for profile in 1b 2b 2u 3b 3u 4; do python3 docs/tools/validate-pdfa-cross.py --strict-tools \ --require-version "$VERAPDF_VERSION" \ --pdfbox "$jar" \ diff --git a/.github/workflows/robustness.yml b/.github/workflows/robustness.yml new file mode 100644 index 0000000..93de31b --- /dev/null +++ b/.github/workflows/robustness.yml @@ -0,0 +1,282 @@ +# Robustness: what the engine does with documents nobody here wrote, and with documents built to break it. +# +# validation.yml checks what the library writes, on every push. This workflow checks what it reads, weekly, +# because its inputs are large and slow: coverage-guided fuzzing of every decoder and of the document parser, +# two public corpora of real and deliberately broken files, and the PDF/A conversion measured against the +# veraPDF test corpus with veraPDF as the judge. None of it gates a pull request; a red run is a defect report. +# +# fuzz SharpFuzz instruments the three engine assemblies and libFuzzer drives one target per job +# (tools/SharpCorePDF.Validation, FuzzTargets.cs). A PdfException is the contract's refusal and +# not a finding; any other exception, a stack overflow or the memory limit is, and the input +# that caused it is uploaded. Reproduce one with: +# dotnet run --project tools/SharpCorePDF.Validation -- replay +# corpora corpus-robustness.py over the veraPDF corpus and the pdf.js test corpus, one process per +# file, under a time limit and a hard managed-heap limit. Fault, crash and timeout fail the run. +# preflight validate-preflight-corpus.py: every PDF/A file of the veraPDF corpus converted for its profile +# and the result judged by veraPDF. Report-only until its first run sets the baseline. +# +# Every external input is pinned: the libFuzzer driver by tag and SHA-256, SharpFuzz in +# .config/dotnet-tools.json, the corpora by commit, veraPDF by version (the same one compliance.yml pins). + +name: Robustness + +on: + schedule: + - cron: '0 3 * * 2' + workflow_dispatch: + inputs: + fuzz-minutes: + description: 'Minutes of fuzzing per target' + required: false + default: '30' + +permissions: + contents: read + +env: + LIBFUZZER_DOTNET_TAG: 'v2025.05.02.0904' + LIBFUZZER_DOTNET_SHA256: 'c2c2a90d94c409a4af339a0d4f244e0442c5a5d249be0f1252ba07871f285958' + VERAPDF_CORPUS_COMMIT: 'bb75f4f0073d9350dfd058c0162a367e6fadf25e' + PDFJS_TAG: 'v6.4.299' + PDFJS_COMMIT: 'd0991a0d53f3bb3a7307e3b83f279c1d117aafb3' + VERAPDF_VERSION: '1.30.4' + VERAPDF_INSTALL: ${{ github.workspace }}/.verapdf + +jobs: + fuzz: + name: Fuzz ${{ matrix.target }} + runs-on: ubuntu-latest + timeout-minutes: 60 + + strategy: + fail-fast: false + matrix: + target: [ document, dct, ccitt, lzw, flate, runlength ] + + steps: + - name: Check out + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Install the .NET SDKs + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6 + with: + dotnet-version: | + 11.0.x + 10.0.x + + - name: Install SharpFuzz and the libFuzzer driver + run: | + set -euo pipefail + dotnet tool restore + curl --fail --silent --show-error --location --proto '=https' --tlsv1.2 \ + --output "$RUNNER_TEMP/libfuzzer-dotnet" \ + "https://github.com/Metalnem/libfuzzer-dotnet/releases/download/${LIBFUZZER_DOTNET_TAG}/libfuzzer-dotnet-ubuntu" + echo "${LIBFUZZER_DOTNET_SHA256} $RUNNER_TEMP/libfuzzer-dotnet" | sha256sum --check + chmod +x "$RUNNER_TEMP/libfuzzer-dotnet" + + # Two builds: an instrumented one for libFuzzer, and a plain one for the seeds and for replaying what + # libFuzzer finds, because instrumented code throws outside the fuzzer (see Program.cs). + - name: Build, then instrument the engine + run: | + set -euo pipefail + dotnet publish ./tools/SharpCorePDF.Validation -c Release -o "$RUNNER_TEMP/plain" + dotnet publish ./tools/SharpCorePDF.Validation -c Release -o "$RUNNER_TEMP/fuzz" + for layer in Domain Application Infrastructure; do + dotnet sharpfuzz "$RUNNER_TEMP/fuzz/SharpCorePDF.$layer.dll" + done + + - name: Seed the corpus + run: | + set -euo pipefail + tool="$RUNNER_TEMP/plain/SharpCorePDF.Validation.dll" + seeds="$RUNNER_TEMP/seeds" + assets=tests/SharpCorePDF.Tests/Assets + case "${{ matrix.target }}" in + document) dotnet "$tool" seed document "$seeds" "$assets/parity/corpus" "$assets/parity/labelled" "$assets/parity/forms" ;; + dct) dotnet "$tool" seed dct "$seeds" "$assets"/jpeg/*.jpg ;; + ccitt) dotnet "$tool" seed ccitt "$seeds" "$assets/ccitt/ccitt-g3.bin" "$assets/ccitt/ccitt-g4.bin" ;; + *) mkdir -p "$seeds" && printf '\x03\x00\x00\x3f\x3f' > "$seeds/empty" ;; + esac + dotnet "$tool" replay "${{ matrix.target }}" "$seeds" + + - name: Fuzz + env: + SCPDF_FUZZ_TARGET: ${{ matrix.target }} + MINUTES: ${{ github.event.inputs.fuzz-minutes || '30' }} + run: | + set -uo pipefail + mkdir -p artifacts/crashes + "$RUNNER_TEMP/libfuzzer-dotnet" \ + --target_path=dotnet --target_arg="$RUNNER_TEMP/fuzz/SharpCorePDF.Validation.dll" \ + -max_total_time=$(( MINUTES * 60 )) -timeout=30 -rss_limit_mb=4096 -max_len=262144 \ + -artifact_prefix=artifacts/crashes/ -print_final_stats=1 \ + "$RUNNER_TEMP/seeds" + status=$? + ls -la artifacts/crashes + if [ -n "$(ls -A artifacts/crashes)" ]; then + echo "::error::libFuzzer saved $(ls artifacts/crashes | wc -l) input(s) that broke the ${{ matrix.target }} target" + exit 1 + fi + exit $status + + - name: Upload what broke the engine + if: failure() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: fuzz-crashes-${{ matrix.target }} + path: artifacts/crashes + if-no-files-found: ignore + retention-days: 30 + + corpora: + name: Public corpora + runs-on: ubuntu-latest + timeout-minutes: 120 + + steps: + - name: Check out + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Install the .NET SDKs + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6 + with: + dotnet-version: | + 11.0.x + 10.0.x + + - name: Fetch the corpora + run: | + set -euo pipefail + # The veraPDF corpus is small enough to clone without blobs and check out at the pinned commit; pdf.js + # is not, so it is cloned one commit deep at its tag and the commit is checked against the pin. + git clone -q --filter=blob:none --sparse https://github.com/veraPDF/veraPDF-corpus.git "$RUNNER_TEMP/verapdf-corpus" + git -C "$RUNNER_TEMP/verapdf-corpus" sparse-checkout set PDF_A-1b PDF_A-2b PDF_A-4 "ISO 32000-1" "ISO 32000-2" "Isartor test files" + git -C "$RUNNER_TEMP/verapdf-corpus" -c advice.detachedHead=false checkout -q "$VERAPDF_CORPUS_COMMIT" + + git clone -q --depth 1 --branch "$PDFJS_TAG" --filter=blob:none --sparse https://github.com/mozilla/pdf.js.git "$RUNNER_TEMP/pdfjs" + git -C "$RUNNER_TEMP/pdfjs" sparse-checkout set test/pdfs + test "$(git -C "$RUNNER_TEMP/pdfjs" rev-parse HEAD)" = "$PDFJS_COMMIT" + + find "$RUNNER_TEMP/verapdf-corpus" "$RUNNER_TEMP/pdfjs" -name '*.pdf' | wc -l + + - name: Build the probe + run: dotnet build ./tools/SharpCorePDF.Validation -c Release + + # The six known files fault on three recorded defects (docs/validation.md): an empty name as a + # dictionary key (issue3188, issue5896, pdfjs_wikipedia, poppler-742-0-fuzzed), a glyph whose box is + # upside down (issue14415) and a date whose offset is beyond 14 hours (TAMReview). + - name: Read every document + run: | + python3 docs/tools/corpus-robustness.py \ + --probe ./tools/SharpCorePDF.Validation/bin/Release/net11.0/SharpCorePDF.Validation.dll \ + --timeout 60 --heap-limit-mb 1024 --report artifacts/corpora.json \ + --known issue3188.pdf --known issue5896.pdf --known pdfjs_wikipedia.pdf \ + --known poppler-742-0-fuzzed.pdf --known issue14415.pdf --known TAMReview.pdf \ + "$RUNNER_TEMP/verapdf-corpus" "$RUNNER_TEMP/pdfjs/test/pdfs" + + - name: Upload the report + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: corpora + path: artifacts/corpora.json + if-no-files-found: warn + retention-days: 30 + + preflight: + name: PDF/A conversion against the veraPDF corpus + runs-on: ubuntu-latest + timeout-minutes: 180 + + steps: + - name: Check out + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Install the .NET SDKs + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6 + with: + dotnet-version: | + 11.0.x + 10.0.x + + - name: Set up the JDK veraPDF runs on + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 + with: + distribution: 'zulu' + java-version: '17' + + - name: Cache the veraPDF installer + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.cache/verapdf + key: verapdf-${{ env.VERAPDF_VERSION }}-installer + + # The same installation compliance.yml performs, so both workflows judge with the same validator. + - name: Install veraPDF + run: | + set -euo pipefail + band="${VERAPDF_VERSION%.*}" + archive="$HOME/.cache/verapdf/verapdf-greenfield-${VERAPDF_VERSION}-installer.zip" + mkdir -p "$(dirname "$archive")" + if [ ! -f "$archive" ]; then + curl --fail --silent --show-error --location \ + --proto '=https' --proto-redir '=https' --tlsv1.2 \ + --output "$archive" \ + "https://software.verapdf.org/releases/${band}/verapdf-greenfield-${VERAPDF_VERSION}-installer.zip" + fi + rm -rf "$VERAPDF_INSTALL" "$RUNNER_TEMP/verapdf" + mkdir -p "$VERAPDF_INSTALL" + unzip -q "$archive" -d "$RUNNER_TEMP/verapdf" + printf '%s\n' \ + '' \ + '' \ + ' ' \ + ' ' \ + " ${VERAPDF_INSTALL}" \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + ' ' \ + '' \ + > "$RUNNER_TEMP/auto-install.xml" + rm -f "/tmp/iz-veraPDF Software.tmp" "${TMPDIR:-/tmp}/iz-veraPDF Software.tmp" + bash "$RUNNER_TEMP/verapdf/verapdf-greenfield-${VERAPDF_VERSION}/verapdf-install" "$RUNNER_TEMP/auto-install.xml" + if [ ! -x "$VERAPDF_INSTALL/verapdf" ]; then + printf '%s\n' '#!/usr/bin/env bash' \ + "exec java -jar \"$VERAPDF_INSTALL\"/bin/cli-*.jar \"\$@\"" \ + > "$VERAPDF_INSTALL/verapdf" + chmod +x "$VERAPDF_INSTALL/verapdf" + fi + "$VERAPDF_INSTALL/verapdf" --version + + - name: Fetch the veraPDF corpus + run: | + set -euo pipefail + git clone -q --filter=blob:none --sparse https://github.com/veraPDF/veraPDF-corpus.git "$RUNNER_TEMP/verapdf-corpus" + git -C "$RUNNER_TEMP/verapdf-corpus" sparse-checkout set PDF_A-1b PDF_A-2b PDF_A-2u PDF_A-3b PDF_A-4 + git -C "$RUNNER_TEMP/verapdf-corpus" -c advice.detachedHead=false checkout -q "$VERAPDF_CORPUS_COMMIT" + + - name: Build the probe + run: dotnet build ./tools/SharpCorePDF.Validation -c Release + + - name: Convert and judge + run: | + python3 docs/tools/validate-preflight-corpus.py \ + --corpus "$RUNNER_TEMP/verapdf-corpus" \ + --probe ./tools/SharpCorePDF.Validation/bin/Release/net11.0/SharpCorePDF.Validation.dll \ + --verapdf "$VERAPDF_INSTALL/verapdf" \ + --report artifacts/preflight.json + + - name: Upload the report + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: preflight + path: artifacts/preflight.json + if-no-files-found: warn + retention-days: 30 diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml new file mode 100644 index 0000000..6bb7cb0 --- /dev/null +++ b/.github/workflows/validation.yml @@ -0,0 +1,232 @@ +# Independent validation: what readers that share no code with this library make of what it writes. +# +# ci.yml answers whether the code builds and the suite passes; compliance.yml whether the archival output +# conforms. This workflow answers a third question -- whether other implementations read the documents the +# way the library meant them -- because a writer that only ever reads its own output back cannot see the +# mistakes it shares with itself. Every check here runs against the example output and against the validation +# corpus that tools/SharpCorePDF.Validation writes, whose manifest states what each document has to say. +# +# qpdf validate-pdf.py: the file parses, every page reads, every stream decodes +# text validate-text.py: pypdf, pdfminer.six and MuPDF extract the lines that were drawn +# encryption validate-encryption.py and the pdf.js leg: four readers open the RC4/AES matrix with the right +# password, refuse the wrong one, and read the revision and the permissions that were asked for +# fonts validate-fonts.py: fontTools and OTS read every embedded program, and the widths agree +# rendering render-compare.py: PDFium and MuPDF paint the same pages +# incremental validate-incremental.py: every revision stands alone, /ID[0] holds, an update only appends +# signatures validate-signatures.py --manifest: pyHanko agrees on integrity, trust and coverage +# fuzz seeds every fuzz target runs over its seeds in process, so a harness that rots is noticed here and +# not in the weekly fuzzing run (robustness.yml) +# hostile corpus-robustness.py over the documents it synthesizes for the failure classes the review named +# arlington validate-arlington.py against the veraPDF Arlington service (report-only until a baseline exists) +# +# --known-defect / --known names a failure that is recorded and not yet fixed. Each is strict: when the +# defect is fixed the check passes, the flag no longer matches, and the run fails until the flag is removed +# in the same change as the fix. The in-suite counterparts are the skipped tests in +# PdfSignatureAttackTests and PdfIncrementalInvariantTests. +# +# The validator versions are pinned in docs/tools/validation-requirements.txt, pdfjs-dist below. + +name: Independent validation + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +permissions: + contents: read + +env: + PDFJS_VERSION: '6.4.299' + +jobs: + readers: + name: Read by other implementations + runs-on: ubuntu-latest + timeout-minutes: 40 + + steps: + - name: Check out + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Install the .NET SDKs + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6 + with: + dotnet-version: | + 11.0.x + 10.0.x + + - name: Install the validators + run: | + set -euo pipefail + python3 -m venv "$RUNNER_TEMP/venv" + "$RUNNER_TEMP/venv/bin/pip" install --quiet -r docs/tools/validation-requirements.txt + echo "$RUNNER_TEMP/venv/bin" >> "$GITHUB_PATH" + npm install --silent --no-save --prefix "$RUNNER_TEMP/pdfjs" "pdfjs-dist@${PDFJS_VERSION}" + + - name: Build the examples and the validation harness + run: | + dotnet build ./examples/SharpCorePDF.Examples -c Release + dotnet build ./tools/SharpCorePDF.Validation -c Release + + - name: Write the documents + env: + TMPDIR: ${{ runner.temp }} + run: | + set -euo pipefail + dotnet run --project ./examples/SharpCorePDF.Examples -c Release --no-build + dotnet run --project ./tools/SharpCorePDF.Validation -c Release --no-build -- corpus "$RUNNER_TEMP/corpus" + + # protected.pdf is encrypted with a password the example makes for the run and prints; the encrypted + # documents qpdf does check are the corpus's, whose passwords the manifest carries + # (validate-encryption.py runs qpdf --check on each of them with its password). + - name: qpdf + run: | + set -euo pipefail + shopt -s nullglob + files=() + for file in "$RUNNER_TEMP"/SharpCorePDF.Examples/output/*.pdf "$RUNNER_TEMP"/corpus/*.pdf; do + case "$(basename "$file")" in protected.pdf|encrypted-*) continue ;; esac + files+=("$file") + done + # Both merge a page of NamedDests.pdf, which states no /MediaBox; the merge copies it without one, + # so the result breaks the rule that every page has a media box, and qpdf assumes Letter. + python docs/tools/validate-pdf.py --known-defect inspected.pdf --known-defect with-warnings.pdf "${files[@]}" + + - name: Text round trip + run: python docs/tools/validate-text.py "$RUNNER_TEMP/corpus" + + - name: Encryption matrix + run: | + set -euo pipefail + python docs/tools/validate-encryption.py "$RUNNER_TEMP/corpus" + node docs/tools/validate-encryption-pdfjs.mjs "$RUNNER_TEMP/corpus" \ + "$RUNNER_TEMP/pdfjs/node_modules/pdfjs-dist/legacy/build/pdf.mjs" + + - name: Embedded fonts + run: | + python docs/tools/validate-fonts.py \ + "$RUNNER_TEMP/SharpCorePDF.Examples/output" \ + "$RUNNER_TEMP/corpus/text-embedded.pdf" "$RUNNER_TEMP/corpus/text-merged.pdf" + + - name: Rendering, PDFium against MuPDF + run: | + python docs/tools/render-compare.py --report-dir artifacts/rendering --exclude protected.pdf \ + "$RUNNER_TEMP/SharpCorePDF.Examples/output" \ + "$RUNNER_TEMP/corpus/text-standard.pdf" "$RUNNER_TEMP/corpus/text-embedded.pdf" \ + "$RUNNER_TEMP/corpus/text-merged.pdf" "$RUNNER_TEMP/corpus/incremental.pdf" \ + "$RUNNER_TEMP/corpus/signed.pdf" + + # id-first: the editor writes a new identifier into both elements of /ID on an appended revision. + # appends-only: the editor's incremental update appends a renumbered copy of the whole document + # rather than the objects it changed. + - name: Incremental update invariants + run: | + python docs/tools/validate-incremental.py "$RUNNER_TEMP/corpus" \ + --known-defect id-first --known-defect appends-only + + # The same copy rewrites the signature dictionary after signing, which is why pyHanko cannot place the + # first signature of signed-then-edited.pdf at the end of a revision. + - name: Signatures, pyHanko + run: | + python docs/tools/validate-signatures.py --manifest "$RUNNER_TEMP/corpus/manifest.json" \ + --known-defect signed-then-edited.pdf:FirstSignature + + - name: Fuzz targets over their seeds + run: | + set -euo pipefail + tool=./tools/SharpCorePDF.Validation/bin/Release/net11.0/SharpCorePDF.Validation.dll + seeds="$RUNNER_TEMP/seeds" + dotnet "$tool" seed document "$seeds/document" tests/SharpCorePDF.Tests/Assets/parity/corpus "$RUNNER_TEMP/corpus" + dotnet "$tool" seed dct "$seeds/dct" tests/SharpCorePDF.Tests/Assets/jpeg/*.jpg + dotnet "$tool" seed ccitt "$seeds/ccitt" tests/SharpCorePDF.Tests/Assets/ccitt/ccitt-g3.bin tests/SharpCorePDF.Tests/Assets/ccitt/ccitt-g4.bin + for target in document dct ccitt; do + dotnet "$tool" replay "$target" "$seeds/$target" + done + + # Each of the four documents reaches a failure class the review named; each is a known defect until the + # change that fixes it removes its --known line. + - name: Hostile documents + run: | + set -euo pipefail + python docs/tools/corpus-robustness.py --synthesize "$RUNNER_TEMP/hostile" + python docs/tools/corpus-robustness.py \ + --probe ./tools/SharpCorePDF.Validation/bin/Release/net11.0/SharpCorePDF.Validation.dll \ + --timeout 120 --report artifacts/hostile.json \ + --known flate-bomb.pdf --known length-chain.pdf --known objstm-count.pdf --known jpeg-selector.pdf \ + "$RUNNER_TEMP/hostile" + + - name: Upload the documents and the reports + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: independent-validation + path: | + artifacts + ${{ runner.temp }}/corpus + ${{ runner.temp }}/SharpCorePDF.Examples/output/*.pdf + if-no-files-found: warn + retention-days: 14 + + arlington: + name: Arlington PDF Model + runs-on: ubuntu-latest + timeout-minutes: 30 + # The service's report format and the writer's baseline are confirmed by the first run on a runner; until + # then the job reports without blocking. Remove continue-on-error and pass --strict with the --accept list + # that run establishes. + continue-on-error: true + + services: + arlington: + image: verapdf/arlington:v1.30.4 + ports: + - 8080:8080 + + steps: + - name: Check out + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Install the .NET SDKs + uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6 + with: + dotnet-version: | + 11.0.x + 10.0.x + + - name: Write the documents + env: + TMPDIR: ${{ runner.temp }} + run: | + set -euo pipefail + dotnet run --project ./examples/SharpCorePDF.Examples -c Release + dotnet run --project ./tools/SharpCorePDF.Validation -c Release -- corpus "$RUNNER_TEMP/corpus" + + - name: Wait for the service + run: | + for attempt in $(seq 1 60); do + curl -sf http://localhost:8080/api/info > /dev/null && exit 0 + sleep 2 + done + echo "::error::the Arlington service did not answer on port 8080" + exit 1 + + - name: Check against the model + run: | + python3 docs/tools/validate-arlington.py --report-dir artifacts/arlington \ + --exclude protected.pdf \ + "$RUNNER_TEMP/SharpCorePDF.Examples/output" \ + "$RUNNER_TEMP/corpus/text-standard.pdf" "$RUNNER_TEMP/corpus/text-embedded.pdf" \ + "$RUNNER_TEMP/corpus/text-merged.pdf" "$RUNNER_TEMP/corpus/incremental.pdf" \ + "$RUNNER_TEMP/corpus/signed.pdf" + + - name: Upload the reports + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: arlington + path: artifacts/arlington + if-no-files-found: warn + retention-days: 14 diff --git a/.gitignore b/.gitignore index 4ca788b..a7b1b5e 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,10 @@ StrykerOutput/ *.sln.docstates *.DotSettings.user +# AI assistant state: prompts, transcripts and local settings stay on the machine that wrote them +.claude/ +CLAUDE.local.md + # Build logs *.binlog msbuild.log diff --git a/.specify/memory/constitution.md b/.specify/memory/constitution.md index af536c8..e45abe8 100644 --- a/.specify/memory/constitution.md +++ b/.specify/memory/constitution.md @@ -1,6 +1,13 @@ + + Exe + net11.0 + preview + SharpCorePDF.Validation + SharpCorePDF.Validation + enable + enable + nullable + true + latest-recommended + false + false + true + + + + + + + + + + + + + + + + + + + + From 8ad4c9e54663e4a4d467365154e25fbe4d360725 Mon Sep 17 00:00:00 2001 From: Andrew Tierney Date: Mon, 16 Nov 2026 11:55:24 +1100 Subject: [PATCH 2/2] Release pdf.js documents through their loading task pdf.js 6 has no PDFDocumentProxy.destroy(), so the encryption check's pdf.js leg reported every document as unopenable: the call threw inside the try that was meant to catch a wrong password. The loading task owns the document and destroying it releases both. The fix was made before the previous commit but an editor saved a stale copy of the file over it. --- docs/tools/validate-encryption-pdfjs.mjs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/tools/validate-encryption-pdfjs.mjs b/docs/tools/validate-encryption-pdfjs.mjs index 8ee5cd1..57a929c 100644 --- a/docs/tools/validate-encryption-pdfjs.mjs +++ b/docs/tools/validate-encryption-pdfjs.mjs @@ -26,8 +26,10 @@ async function open(file, password) { const data = new Uint8Array(await readFile(path.join(corpus, file))); const task = pdfjs.getDocument({data, password, isEvalSupported: false, verbosity: 0}); + // The loading task owns the document in pdf.js 6, which has no PDFDocumentProxy.destroy(): destroying + // the task is what releases both. try { - return await task.promise; + return {task, document: await task.promise}; } catch (error) { await task.destroy(); throw error; @@ -36,8 +38,8 @@ async function open(file, password) { async function refuses(file, password) { try { - const document = await open(file, password); - await document.destroy(); + const {task} = await open(file, password); + await task.destroy(); return false; } catch (error) { return error?.name === "PasswordException"; @@ -51,7 +53,7 @@ for (const entry of manifest.encryption) { const problems = []; try { - const document = await open(entry.file, entry.userPassword); + const {task, document} = await open(entry.file, entry.userPassword); const page = await document.getPage(1); const content = await page.getTextContent(); const text = normalise(content.items.map((item) => item.str + (item.hasEOL ? "\n" : "")).join("")); @@ -61,14 +63,14 @@ for (const entry of manifest.encryption) { problems.push(`page 1 text does not contain ${JSON.stringify(first)}`); } - await document.destroy(); + await task.destroy(); } catch (error) { problems.push(`the user password did not open it: ${error?.name}: ${error?.message}`); } try { - const document = await open(entry.file, entry.ownerPassword); - await document.destroy(); + const {task} = await open(entry.file, entry.ownerPassword); + await task.destroy(); } catch (error) { problems.push(`the owner password did not open it: ${error?.name}: ${error?.message}`); }