Skip to content

shipped · · 13 min

An audit and two releases in one day: hardening a PDF engine before it printed customer documents

Before pdfblaze printed a CRM's quotes, I audited release 1.4.1 the way an attacker with a customer account would use it. Thirteen findings: two High, three Medium, four Low, four Info. The highs and mediums shipped fixed in 1.4.2 and the lows in 1.4.3, all on 2026-12-05. The method, what held up, the guard tests, and what is still open.

This is part 4 of the series Printing a CRM's PDFs without Chrome.

pdfblaze 1.4.1 was a few hours from printing a CRM's quotes, invoices and contracts. Those documents are HTML templates filled with text, logos and images that customers upload. So before the CRM went to production on it, I read the engine and its documentation as someone who controls one customer account would, and tried to break it.

The audit found thirteen things: two High, three Medium, four Low and four Info. Both highs and all three mediums were fixed in 1.4.2, the lows in 1.4.3. The audit and both releases happened on the same day, 2026-12-05. If you run pdfblaze, run 1.4.3 or later. If you use it as a Rust library, also read the note on [patch.crates-io] below.

This post is the overview: how the audit was done, the thirteen findings, the two limits that did not limit, what held up, and what is still open. The two highs get a post each:

What I assumed about the deployment

An audit without a deployment in mind finds either everything or nothing. I wrote down the one I was about to run:

  • A Rails app renders quotes, invoices and contracts from HTML templates.
  • The templates hold customer-supplied text, a customer's logo, and images.
  • It either starts one pdfblaze render process per document, or keeps a pool of pdfblaze worker processes, driven by the Ruby client in examples/, the way docs/server.md shows.

The second option matters even though the CRM uses the first. The server guide and its worker clients were new in 1.4.1. Anyone reading that guide would copy the pool, so the pool was in scope as if it were code I ran.

Method

The audit was a white-box review of the 1.4.1 source, plus a proof of concept for every finding I could reproduce, run against a release build on macOS arm64. Each finding is marked Confirmed if a proof of concept reproduced it and Suspected if it rests on reading the code. Nothing in the repository changed during the audit; it ran from a detached checkout.

I took the attacker's position literally. Someone with a customer account controls a logo file, some text, and, in templates that allow custom styling, some CSS. They can make their own renders slow. They cannot touch the server's files or the worker's command line. The question for each part of the engine was: what can those inputs make it do that the operator did not ask for?

Five things were out of reach on that machine, and I said so in the report rather than guess:

Not testedWhy
Disk full, cargo auditThe test disk had 143 MiB free; installing cargo-audit failed
The C libraryIts build failed for the same reason
FuzzingA nightly cargo-fuzz build needs several GiB of disk
The Linux sandbox (Landlock, seccomp)No Linux machine was available
Cryptography of the signing pathOut of time; only the escaping of its text fields was read

Thirteen findings

figure 1 · thirteen findings, where each was fixed

2 high · 3 medium · 4 low · 4 info

  1. H1high

    A PDF passed off as a logo overflows the stack and aborts the process

    10,312-byte file; an array nested 5,000,000 levels deep in a compressed object stream; exit 134

    fixed in
    1.4.2
    guard
    survives_pdf_files_with_deeply_nested_objects · merges_pdfs_with_deeply_nested_objects
  2. H2high

    The documented worker pool hands one caller's PDF to the next

    'Bob' received 195,932 bytes holding 'Alice's' invoice

    fixed in
    1.4.2
    guard
    the Ruby and Python clients' own self-check: an interrupted worker is not alive
  3. M3medium

    CSS counters get around the time limit and the memory budget

    3,000 counters × 3,000 elements: 29.3 s and 702 MiB at a 1 s limit and a 64 MiB budget

    fixed in
    1.4.2
    guard
    counts_long_counter_lists_against_the_budget
  4. M4medium

    Multi-column layout gets around the time limit

    400,000 words in 1,000 columns: still running at 120 s with a 1 s limit

    fixed in
    1.4.2
    guard
    ends_multi_column_layout_when_its_time_is_up
  5. M5medium

    Release build jobs held write and signing tokens

    workflow-level permissions; checkout kept its token; zig installed without hashes

    fixed in
    1.4.2
    guard
    none in code: read-only build jobs, attestation in its own job
  6. L6low

    Documentation examples had no timeout and no limits

    five 81 MP image bombs reach 1,337 MiB under the default budget

    fixed in
    1.4.2 docs
    guard
    none: docs/server.md
  7. L7low

    merge --keep-links copied javascript: and file: links

    both survived into the merged PDF

    fixed in
    1.4.3
    guard
    leaves_out_links_with_schemes_render_does_not_write
  8. L8low

    Some work runs past the time limit

    4–9× over on documents made to be slow: 3.9 s and 9.1 s

    fixed in
    1.4.2 checks + 1.4.3 SECURITY.md
    guard
    none: documented as a remaining risk
  9. L9low

    Client error handling: no deadline on a frame body; odd failures put a broken worker back

    code reading

    fixed in
    1.4.2
    guard
    deadline reads in both example clients
  10. I10info

    Worker frame memory amplification (the caller is trusted)

    a 40 MB header made the worker take 861 MiB

    fixed in
    1.4.3
    guard
    refuses_frames_with_too_many_data_blocks (65,536 cap)
  11. I11info

    SECURITY.md's 'no unsafe' claim ignored the C library

    code reading

    fixed in
    1.4.2 docs
    guard
    none: SECURITY.md
  12. I12info

    Gaps in the Linux seccomp denylist (signals, TIOCSTI)

    code reading; no Linux on the audit machine

    fixed in
    1.4.3
    guard
    signals_only_its_own_process · refuses_to_type_into_the_terminal (CI only)
  13. I13info

    The docs put the engine's stderr into user-facing errors

    code reading

    fixed in
    1.4.2 docs
    guard
    none: docs/server.md logs it instead
Every row is one finding of the audit of 1.4.1: what it was, the evidence, the release that fixed it, and the test or check that now stands guard. The highs and mediums went out in 1.4.2; the lows and most infos in 1.4.3. Rows with no test say so.

The two highs are the ones that would have hurt the CRM or anyone copying the docs.

H1: a PDF passed off as a logo. pdfblaze decides an image's format from its bytes, not its name, so a file called logo.png that starts with %PDF- is drawn as a PDF image. A 10,312-byte file whose one object is an array nested 5,000,000 levels deep, kept in a Flate-compressed object stream, made the PDF parser recurse once per level until the stack ran out. Rust aborts on a stack overflow; it cannot be caught. The render process died with exit code 134, a worker died with every render it held, and the C library would take its host process with it. Part 5 is the whole story: why the engine's existing depth guard missed it, why fuzzing missed it, and the vendored fix.

H2: the documented pool. In the server guide's Rails pool, a request timeout that was not the client's own error put the worker back in the pool with an answer still on its way. The next request on that worker read it. In the proof of concept, "Bob" received 195,932 bytes holding "Alice's" invoice. Nothing on either side checked that an answer belonged to the request that read it. Part 6 walks through it frame by frame.

Two limits that did not limit

pdfblaze has a --time-limit and a --memory-budget. The audit's job for them was simple: find a document that ignores them. It found two. Both need customer control of CSS, which a template with a custom <style> block gives; escaped customer text alone cannot reach them.

M3: CSS counters. A 47 KB document puts counter-increment on 3,000 counters across 3,000 elements and shows them with counters() in ::before. At a 1 s time limit and a 64 MiB budget it ran 29.3 s and reached 702 MiB:

CountersTime at --time-limit 1Peak
1,0001.56 s95 MiB
2,0007.97 s323 MiB
3,00029.3 s702 MiB

A profile put all of the time in finding counters. Looking one up was a linear scan of every counter in scope, done for every counter on every element, so the work grew roughly with the cube of the size. The box-tree builder that does this never looked at the clock, and the counter lists it built were not charged to the memory budget. The fix in 1.4.2 does both: an index makes the lookup stop scanning, and long lists in content, the counter-* properties and string-set count against the budget. The guard renders paragraphs that each carry 1,000 counters, expects a 6 MiB budget to stop it, and expects a 64 MiB budget to let it through:

terminal
let held = exceeded_memory(render(&document, Limits::new().memory(Some(6 * MIB))));
assert_eq!(held[0], "styles");
// With room for them, it renders.
render(&document, Limits::new().memory(Some(64 * MIB))).expect("rendered");

M4: multi-column layout. column-count: 1000 over 400,000 words, a 2 MB document, was still running when my watchdog killed it at 120 s with a 1 s limit. 200,000 words took 41 s; 100,000 took 5 s. The same text without columns stopped at the limit in 1.14 s. The clock was checked once, as a paragraph began, and multi-column layout then laid out the rest of the paragraph again for each of the thousand columns. 1.4.2 checks the time on every line. Its guard, ends_multi_column_layout_when_its_time_is_up, gives 50,000 words a 100 ms limit, expects limit.time, and fails if that takes 10 s or more.

I measured the same documents again on the released 1.4.3, median of three runs on macOS arm64:

figure 2 · the slow documents, before and after
  • 3,000 counters × 3,000 elements --time-limit 1

    1.4.129.3 s, 702 MiB: limit ignored

    1.4.3stops at 1.35 s (limit.time), peak 607 MiB

  • same document --memory-budget 64

    1.4.1budget ignored (the same 29.3 s run)

    1.4.3stops at 0.42 s (limit.memory), peak 358 MiB

  • 400,000 words in 1,000 columns --time-limit 1

    1.4.1still running at 120 s (killed)

    1.4.3stops at 1.08 s, peak 314 MiB

seconds · log scale

Seconds on a log scale; the dashed line is the 1 s limit the audit set. On 1.4.1 these documents ran for 29.3 s, and past 120 s; on 1.4.3 each stops just past its limit. With a 64 MiB budget the process still peaked at 358 MiB before the stop: the budget is an estimate that ends the document, not a cap on the process.
Case1.4.1 (audit)1.4.3
3,000 counters × 3,000 elements, --time-limit 129.3 s, 702 MiB, limit ignoredstops at 1.35 s (limit.time), peak 607 MiB
same, --memory-budget 64budget ignoredstops at 0.42 s (limit.memory), peak 358 MiB
400,000 words in 1,000 columns, --time-limit 1still running at 120 sstops at 1.08 s, peak 314 MiB
1,000 counters, no limits1.56 s, 95 MiB (with limits)0.63 s, 204 MiB

Two things in that table need saying plainly.

The memory budget is an estimate that stops a document, not a cap on the process. At a 64 MiB budget the process still peaked at 358 MiB before the stop, because the budget counts the large parts of a document and not everything the process holds. On Linux, --memory-limit is the hard cap; use both.

The last row is not like for like: the audit ran 1,000 counters with limits set, and I ran 1.4.3 without them. It is the pair of numbers I have, not a clean comparison, and certainly not a memory win. With no limits at all, 3,000 × 3,000 counters still takes 5.8 s and 1.7 GB on 1.4.3. A document made to be slow still finishes eventually; the limits are what end it early.

Finally, a fix to layout can change what layout produces. I rendered the CRM's 13 quote templates on 1.4.1 and 1.4.3, seven runs each: 311.6 ms in total before, 304.6 ms after, and every page pixel-identical at 80 dpi.

The release workflow

M5 was about how the binaries are built, not what they do. The release workflow granted contents: write and id-token: write to every job, and the build jobs compile the build scripts of every dependency, installed zig from pip without hashes, and handed a checkout that still held its token to a third-party FreeBSD VM action. A compromised build.rs could have pushed to the repository or, worse, asked for a signing token and attested a backdoored binary as this workflow, which is exactly the check gh attestation verify is meant to provide.

In 1.4.2 the build jobs get a token that only reads and do not keep it in the checkout, attestation runs in its own job that builds nothing, only the job that drafts the release can write, and zig is installed against pinned hashes. Part 8 covers the release pipeline in full.

The lows and the infos

None of these was an attack on its own. Each made one of the others easier or worse.

  • L6, the docs' defaults. The one-process examples had no --time-limit, the Ruby one had no timeout at all, and the pool kept the 2 GiB default budget. Five 81 MP image bombs reached 1,337 MiB within that default. 1.4.2's docs pass --time-limit 20, kill a process that hangs, and give the pool a memory budget of its own.
  • L7, merge --keep-links. It copied javascript: and file: link targets from input PDFs. 1.4.3 keeps only the schemes render would write: http, https, mailto, tel and ftp.
  • L8, overrun. Parsing and some resource work run to their end before the next time check: 3.9 s and 9.1 s against a 1 s limit, 4–9× over. That is bounded by input size, so 1.4.3 documents it in SECURITY.md rather than pretending the limit is a wall. Keep the caller's own timeout.
  • L9, client error handling. The example clients put a deadline on the first byte of a frame but not the rest, and a short read raised the wrong error. Fixed with part 6.
  • I10, frame amplification. A 40 MB worker header listing a huge number of empty data blocks made the worker take 861 MiB. The worker's caller is trusted, but 1.4.3 refuses frames with more than 65,536 data blocks anyway.
  • I11. SECURITY.md said pdfblaze had no unsafe code beyond one malloc_trim, which forgot the C library's interface. 1.4.2 corrected it.
  • I12, seccomp gaps. The Linux sandbox allowed signals to other processes of the same user and the TIOCSTI ioctl, which types into the terminal a process was started from. 1.4.3 refuses signals to anything but pdfblaze's own process and refuses TIOCSTI and TIOCLINUX.
  • I13. The docs' error handling put the engine's standard error, with template file names and URLs, into exception messages. 1.4.2's docs log it and show the user a message of their own.

What held up

Most of what I threw at it did nothing, which is worth writing down as carefully as the findings:

  • Reading local files. 24 attempts: ../, encoded and double-encoded dots, backslashes, symlinks out of the base, <base href="file:///etc/">, @import, @font-face, SVG <use> and <image>, iframes and srcdoc. Only files inside the base were shown. The resolver decodes, canonicalises, then checks the prefix, in that order, which is the right order.
  • XXE and XInclude in SVG and XHTML: entities not expanded, XInclude ignored.
  • SSRF. The engine has no HTTP client. URLs with a scheme go only to the caller's loader, and a local listener saw nothing.
  • PDF output injection. javascript: in every casing and spacing I tried, vbscript:, data:, file: links: all dropped. Titles, metadata and form fields are escaped.
  • Malformed worker frames. Absurd lengths, truncated frames, headers that are not JSON: each ends the worker cleanly, at a maximum resident size of 8 MiB, with no large allocation.
  • Many denial-of-service shapes. 20,000 page breaks gave 10,000 pages in 0.38 s; a 196 MP PNG peaked at 430 MiB, inside the budget; deep elements, CSS nesting, billion laughs in SVG, iframe recursion all stopped at their limits.

How I know the fixes hold

Every fix in 1.4.2 and 1.4.3 that changed code leaves a test behind, and the board above names it. Where a fix changed only documentation or CI configuration, the board says "none" rather than inventing a guard.

The tests carry the audit's own inputs where they can. The H1 test renders the audit's 10 KB file as a logo.png and as a PDF image, and expects a clean render; the merge test feeds both it and a 200,000-level uncompressed array to merge. Beyond the tests, the audit's proofs of concept were run again against the released binaries: the logo file exits 134 on 1.4.1 and renders on 1.4.2 and 1.4.3. A final run of 20 security probes on the release build leaked nothing.

One gap I will not paper over. The 1.4.3 sandbox tests, signals_only_its_own_process and refuses_to_type_into_the_terminal, pass on CI on Linux x64 and arm64, but I did not take the fix out and watch them fail, because I had no Linux machine at hand. A test that passes both ways is not a test, and until someone runs that check, those two are a claim.

Upgrading

Binaries: download 1.4.3 from the release page and check it against SHA256SUMS. If you copied the worker client or the pool from 1.4.1's docs, copy them again from 1.4.3: the fix for H2 is in that code, not in the engine.

Rust library users need one more line. The H1 fix lives in a vendored copy of the PDF parser, and Cargo applies a [patch.crates-io] entry only from the top-level project, so pdfblaze's own cannot reach your build:

terminal
[dependencies]
pdfblaze = { git = "https://github.com/sundarshahi/pdfblaze", tag = "v1.4.3" }

[patch.crates-io]
hayro-syntax = { git = "https://github.com/sundarshahi/pdfblaze", tag = "v1.4.3" }

What I'd do differently, and what is still open

  • Audit before the docs ship, not after. The pool bug lived in a guide I had published hours before. An example in the docs is code that other people run; it deserves the same review as the engine.
  • Fuzz with large inputs. The fuzz targets for PDFs cap input at 64 KiB, which is why fuzzing never reached H1. A deep-nesting seed and a larger -max_len for the PDF targets are still to do.
  • The budget is still an estimate. The CRM's largest documents peaked at 415–583 MB under a 256 MiB budget. The real fix there is a hard limit from the operating system, and the CRM's follow-up is a Linux --memory-limit.
  • Counters without limits. 5.8 s and 1.7 GB at 3,000 × 3,000. Set --time-limit and --memory-budget in production; the defaults are no time limit and 2 GiB.
  • Sandbox. In-process code loading through memfd or mprotect with execute permission is not filtered; exec is blocked. The sandbox tests need a revert check on real Linux.
  • Not tested at all: disk full, the C library, fuzzing, the Linux sandbox, and the cryptography of the signing path. Those are the next audit, not footnotes to this one.

Working through something like this? I help teams ship AI and cloud systems that hold up, and cost what they should.