Skip to content

fix: verify PDFium archives and download them atomically - #69

Merged
billdenney merged 3 commits into
mainfrom
claude/pdfium-download-cache
Sep 27, 2026
Merged

billdenney merged 3 commits into
mainfrom
claude/pdfium-download-cache

Conversation

@billdenney

Copy link
Copy Markdown
Member

tools/download-pdfium.R downloaded straight into its persistent cache.
Two failure modes are reproduced:

  • An interrupted transfer (half an archive served from a local HTTP
    server) left a partial file. R's libcurl code deletes the
    destination only when no bytes arrived, so every later install took
    the "Using cached archive" branch and failed.
  • A truncated cached archive was worse: utils::untar() only warns when
    tar fails, so the script exited 0 and left a truncated libpdfium.so
    in inst/lib for the link step to trip over.

Now:

  • tools/pdfium-checksums.txt pins the SHA-256 of every archive
    detect_platform() can request, with a release: line that must match
    tools/pdfium-version.txt. The install stops if the file is for
    another release, has no entry for the archive, or is malformed. This
    is a mechanical gate for pin bumps.
  • tools/update-pdfium-checksums.R regenerates the file. Its output for
    chromium/8066 equals GitHub's published asset digests.
  • Every archive (downloaded, cached or vendored) is verified before it
    is unpacked. On R >= 4.5 that is an exact SHA-256 match. Older R has
    no tools::sha256sum(), so it only checks that the archive lists
    completely, and says so.
  • Downloads go to a temporary file in the cache directory and are
    renamed into place only after they verify.
  • A bad cache entry is replaced. A bad vendored archive or download
    stops the install.
  • Warnings while unpacking are errors.

ADR-027 records this. It supersedes ADR-003's unimplemented "sentinel
filename" consequence and ADR-006's rejection of hash pinning, which
rested on the same false premise. dev/architecture.md's bump procedure
gains the regeneration step. The new tests run the script offline
against synthetic archives, using file:// URLs for the download path.
Five of them fail against the previous script.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

billdenney and others added 3 commits September 27, 2026 15:41
tools/download-pdfium.R downloaded straight into its persistent cache.
Two failure modes are reproduced:
- An interrupted transfer (half an archive served from a local HTTP
  server) left a partial file. R's libcurl code deletes the
  destination only when no bytes arrived, so every later install took
  the "Using cached archive" branch and failed.
- A truncated cached archive was worse: utils::untar() only warns when
  tar fails, so the script exited 0 and left a truncated libpdfium.so
  in inst/lib for the link step to trip over.

Now:
- tools/pdfium-checksums.txt pins the SHA-256 of every archive
  detect_platform() can request, with a release: line that must match
  tools/pdfium-version.txt. The install stops if the file is for
  another release, has no entry for the archive, or is malformed. This
  is a mechanical gate for pin bumps.
- tools/update-pdfium-checksums.R regenerates the file. Its output for
  chromium/8066 equals GitHub's published asset digests.
- Every archive (downloaded, cached or vendored) is verified before it
  is unpacked. On R >= 4.5 that is an exact SHA-256 match. Older R has
  no tools::sha256sum(), so it only checks that the archive lists
  completely, and says so.
- Downloads go to a temporary file in the cache directory and are
  renamed into place only after they verify.
- A bad cache entry is replaced. A bad vendored archive or download
  stops the install.
- Warnings while unpacking are errors.

ADR-027 records this. It supersedes ADR-003's unimplemented "sentinel
filename" consequence and ADR-006's rejection of hash pinning, which
rested on the same false premise. dev/architecture.md's bump procedure
gains the regeneration step. The new tests run the script offline
against synthetic archives, using file:// URLs for the download path.
Five of them fail against the previous script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the drop-CRAN docs (ADR-026). Only the ADR index
conflicted: the ADR-003 status cell now names both superseding
decisions (ADR-026 for the CRAN-submission wording, ADR-027 for the
download-integrity consequence), and the ADR-026 and ADR-027 rows
stay in number order. Rcpp exports and roxygen output are unchanged;
the full suite passes under MALLOC_CHECK_=3 (3354 passed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@billdenney
billdenney merged commit 9c40202 into main Sep 27, 2026
12 checks passed
@billdenney
billdenney deleted the claude/pdfium-download-cache branch September 27, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant