Skip to content

🐛 Escape appName as a PDF name in Prop_Build - #336

Open
fstandhartinger wants to merge 3 commits into
vbuch:developfrom
fstandhartinger:fix/escape-app-name
Open

fstandhartinger wants to merge 3 commits into
vbuch:developfrom
fstandhartinger:fix/escape-app-name

Conversation

@fstandhartinger

@fstandhartinger fstandhartinger commented Nov 18, 2026 •

Copy link
Copy Markdown

Fixes #335.

appName was written into /Prop_Build /App /Name as a PDF name without escaping, so My App came out as /Name /My App and poppler reported Dictionary key must be a name object.

Change

  • @signpdf/utils gets escapePdfName (ISO 32000-1 §7.3.5): the value is encoded as UTF-8, and every byte outside !–~, every delimiter and # itself is written as #XX (uppercase hex, which pdf-lib decodes). Values that need no escaping come back unchanged, so signpdf / app-name-signpdf produce the same bytes as before.
  • placeholder-pdfkit and placeholder-pdfkit010 escape appName before handing it to the writer. placeholder-plain goes through placeholder-pdfkit010, so it is covered too. placeholder-pdf-lib is unchanged, because pdf-lib's PDFName already escapes.
  • Tests: unit tests for escapePdfName, plus one appName: 'My App' case in each of the three placeholder packages. All three placeholder cases fail on develop and pass with the change.

About dist: I committed the rebuilt utils/dist (new export) and the two pdfkitAddPlaceholder.js builds, because the pdfkit-compatibility job and placeholder-plain's tests import the committed builds. The other lines that changed in those two files come from src that the committed build didn't include yet (removed eslint comments, the widget's /P). I left every other dist file alone.

Checked locally (Node 26, lerna run lint and lerna run test green, coverage thresholds met; placeholder-pdfkit also against pdfkit 0.15.0):

placeholder appName /App before /App after pdfinfo after
plain My App << /Name /My App >> << /Name /My#20App >> no errors
pdfkit010 (pdfkit 0.10) My App << /Name /My App >> << /Name /My#20App >> no errors
pdfkit (pdfkit 0.11) My App << /Name /My App >> << /Name /My#20App >> no errors
all three Résumé (signer) raw bytes and parentheses /R#C3#A9sum#C3#A9#20#28signer#29 no errors

The pdfkit-based placeholders were affected as well, as the issue suspected. Every output was then signed with signpdf.sign and the test P12 certificate, and pdfsig reports "Signature is Valid" for each of them.

I used Claude Code (AI) to help write this change. I reviewed it and ran everything above myself.

đŸ€– Generated with Claude Code

fstandhartinger and others added 2 commits November 18, 2026 08:26
appName was written into /Prop_Build /App /Name verbatim, so a value with a
space, a delimiter or a non-ASCII character produced an invalid dictionary
(e.g. "/Name /My App"). Add escapePdfName to @signpdf/utils (ISO 32000-1
7.3.5: UTF-8 bytes outside ! to ~, delimiters and # become #xx) and use it in
placeholder-pdfkit and placeholder-pdfkit010, which placeholder-plain goes
through. Names that need no escaping are unchanged. placeholder-pdf-lib
already escapes through pdf-lib's PDFName.

utils/dist is updated for the new export because the pdfkit-compatibility
CI job tests placeholder-pdfkit against the committed utils build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
placeholder-plain's tests and CI import placeholder-pdfkit010 from its committed
dist, so the escaping has to be in the build. Generated with `lerna run build`;
the other differences in these two files are the existing src (removed eslint
comments, the widget's /P entry) that the committed build did not have yet.

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

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — fstandhartinger:fix/escape-app-name into vbuch:develop

vbuch commented Nov 19, 2026

Copy link
Copy Markdown
Owner

[P2] Emit uppercase hex escapes at escapePdfName.js:17.

pdf-lib 1.17.1 only decodes uppercase hex escapes. I reproduced PDFKit output with appName: 'Résumé' being read as literal R#c3#a9sum#c3#a9, which changes the metadata when reserialized. Uppercase escapes preserve the intended UTF-8 bytes. Add .toUpperCase() to the hex conversion and a pdf-lib round-trip regression test.

All 123 tests across the four affected packages passed, with coverage thresholds met.

<Reviewed with GPT-6.1 Sol>

pdf-lib 1.17.1 only decodes uppercase #XX escapes in names, so an appName
like "Résumé" written as R#c3#a9sum#c3#a9 was read back literally and
re-serialized as R#23c3#23a9..., changing the metadata. Uppercase escapes
round-trip through pdf-lib.

Adds a pdf-lib round-trip test (fails with lowercase escapes) and pdf-lib
as a devDependency of @signpdf/utils (already in yarn.lock via
placeholder-pdf-lib). utils/dist rebuilt.

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

Copy link
Copy Markdown
Author

Thanks, confirmed and fixed in 7afda81.

I reproduced it first: PDFName.of('R#c3#a9sum#c3#a9') in pdf-lib 1.17.1 decodes to the literal text and re-serializes as /R#23c3#23a9sum#23c3#23a9, while R#C3#A9sum#C3#A9 decodes to the UTF-8 bytes and re-serializes unchanged.

  • escapePdfName now emits uppercase hex (.toUpperCase()), src and the rebuilt utils/dist.
  • New test "round-trips through pdf-lib without changing the name" for My App, RĂ©sumĂ© (signer), all delimiters and \t/\n: it checks the decoded bytes and that asString() returns our escaped name unchanged. It fails with the old lowercase output. pdf-lib (^1.17.1, already in yarn.lock) is added as a devDependency of @signpdf/utils for it.
  • End to end: plain, pdfkit010 and pdfkit placeholders with RĂ©sumĂ© (signer) now write /R#C3#A9sum#C3#A9#20#28signer#29. Loading each output with pdf-lib gives back RĂ©sumĂ© (signer), and doc.save() keeps the name byte-identical. pdfinfo shows no errors and pdfsig validates the signature.
  • lerna run lint and lerna run test are green locally (utils 76 tests).

The PR description now shows the uppercase form as well. (Prepared with Claude Code.)

This branch has not been deployed

No deployments
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.

appName containing a space produces an invalid /Prop_Build dictionary

3 participants