Skip to content

chore: bump go-pdfkit/pdfkit v0.21.0 -> v0.28.0 - #463

Open
tannevaled wants to merge 1 commit into
mainfrom
worktree-agent-ab89219a4d3456422
Open

tannevaled wants to merge 1 commit into
mainfrom
worktree-agent-ab89219a4d3456422

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Bump github.com/go-pdfkit/pdfkit v0.21.0 -> v0.28.0 (root go.mod and
bench/go.mod, same pattern as the earlier dlclark/regexp2 bump in
550721e, Refs #454). go mod tidy also pulls in the transitive version bumps
pdfkit's own updated go.mod requires (MVS): go-gfx/gfx,
go-images/images, go-opentype/opentype, go-pdfkit/reader,
go-widgets/painter, andybalholm/brotli. None of v0.22.0-v0.28.0 renamed
or removed an exported API per the release notes, and go build ./...
confirms it empirically.

Per-version highlights relevant to this repo: v0.22.0 go1.27.3 + fuzzed
parser fixes; v0.23.0 a PNG-allocation ceiling; v0.24.0 page transitions
(additive); v0.25.0 ImportPDFPage (additive); v0.26.0 image handles,
O(1) SetAlpha, Page.ContentLen; v0.27.0 Document.Write now streams
instead of buffering (same external signature, confirmed by compiling and
testing the existing call sites); v0.28.0, the one this bump is for,
adds /Predictor 15 (PNG-style per-row filtering) on raster images
before Flate compression, kept only when it beats plain deflate —
measured 26-40% smaller on photographs (upstream go-pdfkit/pdfkit#67,
Refs go-pdfkit/pdfkit#67, already merged there);
Options.NoImagePredictor reverts to the old bytes.

The risk this bump was flagged against

A peer go-pdfkit session warned that rsc.io/pdf (used by
pdfcanvas/pdfcanvas_test.go and pdfcanvas/userselect_test.go on main
to read a rendered PDF back for verification) panics on /Predictor 15.
Confirmed empirically with a throwaway diagnostic test (not committed):

  • Predictor 15 is chosen for pdfcanvas_test.go's <img> fixture
    (confirmed via its actual /DecodeParms:
    <</BitsPerComponent 8 /Colors 3 /Columns 40 /Predictor 15>>).
  • Calling .Reader() on that image XObject directly does panic in
    rsc.io/pdf ("unknown predictor 15").
  • But neither existing test ever calls .Reader() on an image XObject's
    stream — pdfcanvas_test.go only inspects the page's Contents stream,
    font structures and ToUnicode tables; userselect_test.go has no
    raster image at all. So the panic path is never exercised by anything
    on main today. gotest ./pdfcanvas/... and go test -race ./pdfcanvas/... are both green.

No code change was needed to handle this — the risk is real for a test
that reads image bytes back through rsc.io/pdf, but nothing currently
does.

#457 (Refs #457, stays open, not finished by this PR)

Read #457's diff (pdfcanvas/jpegphoto_test.go, not merged, a different
branch from this session). Its soleImageFilterAndLen helper also uses
rsc.io/pdf to read a rendered PDF back, but it only inspects the image
XObject's /Filter name and /Length — it never calls .Reader() to
decode the stream. So it would not hit the Predictor-15 panic either, and
no comment was left on #457: the conditional risk this task asked me to
flag there did not materialize once checked against the actual diff.
Separately, #457 re-encodes opaque images >=200x200px as JPEG
(/DCTDecode), which bypasses FlateDecode/Predictor entirely for that
case anyway.

Testing

  • go build ./..., gotest ./... (root module): clean.
  • go test -race ./pdfcanvas/...: clean.
  • gofmt -l .: 5 pre-existing unformatted files (css/clamp_test.go,
    css/modern_test.go, js/opfs_test.go, js/testdata/gen_add_wasm.go,
    js/worker_test.go), unchanged from origin/main, untouched by this
    change.
  • go vet ./..., govulncheck ./...: clean.

🤖 Generated with Claude Code

v0.28.0 adds /Predictor 15 (PNG-style per-row filtering) on raster images
before Flate compression, kept only when smaller than plain deflate — a
26-40% size win on photographs (pdfkit PR #67). Also picks up v0.22.0's
parser fuzzing fixes, v0.23.0's PNG-allocation ceiling, v0.24.0's page
transitions, v0.25.0's ImportPDFPage, v0.26.0's image handles/O(1)
SetAlpha/Page.ContentLen, and v0.27.0's streaming Document.Write. None of
these renamed or removed an exported API; go.mod/go.sum (root and bench/,
same pattern as 550721e) carry the transitive bumps MVS pulls in from
pdfkit's own updated go.mod (go-gfx/gfx, go-images/images,
go-opentype/opentype, go-pdfkit/reader, go-widgets/painter,
andybalholm/brotli).

Checked the real risk a peer go-pdfkit session flagged: whether Predictor
15 would make main's existing rsc.io/pdf-reading tests
(pdfcanvas_test.go, userselect_test.go) panic ("unknown predictor 15" is
rsc.io/pdf's own behavior, confirmed with a throwaway diagnostic test).
Empirically: Predictor 15 IS chosen for pdfcanvas_test.go's <img> fixture
(confirmed via its /DecodeParms), but neither existing test ever calls
.Reader() on an image XObject's stream — they only inspect the page
Content stream and font ToUnicode tables — so no existing test reads a
Predictor-15-compressed stream and none panics. gotest ./pdfcanvas/...
and go test -race ./pdfcanvas/... are both green.

Full gate: gotest ./..., go vet ./..., govulncheck ./... clean.
gofmt -l . lists 5 pre-existing unformatted files (css/clamp_test.go,
css/modern_test.go, js/opfs_test.go, js/testdata/gen_add_wasm.go,
js/worker_test.go), unchanged from origin/main and untouched by this
bump.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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