Skip to content

Add cmd/pdfdump smoke tests against hostile input#15

Merged
pgundlach merged 1 commit into
mainfrom
claude/cmd-pdfdump-smoke-test
Jun 23, 2026
Merged

Add cmd/pdfdump smoke tests against hostile input#15
pgundlach merged 1 commit into
mainfrom
claude/cmd-pdfdump-smoke-test

Conversation

@fank

@fank fank commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Why

pdfdump is the real-world entry point a user runs on an untrusted file. If it panics on a hostile PDF, the "never crash on untrusted input" mandate is violated at its most visible point — yet cmd/pdfdump was 0% covered because main() is untestable (global flag state, log.Fatal).

Change

Extract run(args []string, stdout io.Writer) error; main() becomes a thin wrapper that maps the error to log.Fatal (and treats -h as exit 0). No behavior change for real use.

Tests

  • TestRunHostileInputsNoPanic — empty, garbage, broken-xref-recovery, NUL bytes, and an unclosed dict each yield a graceful error or valid JSON, never a panic.
  • TestRunValidFixtures — every testdata/fixtures/*/input.pdf dumps to JSON (with -stream-content, exercising the inline-content path).
  • TestRunArgErrors — no-arg and missing-file both error.

Coverage: cmd/pdfdump 0% → 74%; run 87%.

pdfdump is the entry point run on untrusted files, but main() was
untestable (global flag state, log.Fatal). Extract run(args, stdout)
error so the command can be exercised; main() stays a thin wrapper.

Tests assert hostile inputs (empty, garbage, broken xref, NUL bytes,
unclosed dict) yield a graceful error or valid JSON — never a panic —
and that every testdata fixture dumps successfully.
@fank fank marked this pull request as ready for review June 22, 2026 22:06
@fank fank requested a review from pgundlach June 22, 2026 22:06
@pgundlach pgundlach merged commit 0430eb5 into main Jun 23, 2026
1 check passed
@pgundlach pgundlach deleted the claude/cmd-pdfdump-smoke-test branch June 23, 2026 05:18
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.

2 participants