Skip to content

Fix page dict string value corruption in createIncPageUpdate#134

Draft
fredgig wants to merge 1 commit intodigitorus:mainfrom
fredgig:fix/page-dict-string-values
Draft

Fix page dict string value corruption in createIncPageUpdate#134
fredgig wants to merge 1 commit intodigitorus:mainfrom
fredgig:fix/page-dict-string-values

Conversation

@fredgig
Copy link
Copy Markdown
Contributor

@fredgig fredgig commented Apr 6, 2026

Bug

createIncPageUpdate writes page dictionary string values (like /LastModified, /CreationDate) using Go double quotes instead of PDF parenthesized strings.

This breaks multi-signature PDFs. After the first signature rewrites the page dict, subsequent calls to pdf.NewReader panic:

unexpected keyword "\"D:20220711015152-06'00'\"" parsing object

Root Cause

The default case uses page.Key(key).String() to serialize values. Value.String() calls objfmt(), which runs strconv.Quote() on string values, producing "text" instead of (text).

default:
    page_buffer.WriteString(fmt.Sprintf("  /%s %s\n", key, page.Key(key).String()))

A page entry like:

/LastModified (D:20220711015152-06'00')

Gets rewritten as:

/LastModified "D:20220711015152-06'00'"

Double quotes aren't valid PDF string syntax. The lexer treats it as an unexpected keyword and panics.

Repro

  1. Take a PDF with a string value in a page dictionary (e.g. /LastModified)
  2. Sign with 2+ signature fields on pages containing that string
  3. First signature corrupts the string, second signature panics on parse

Fix

Check for pdf.String kind and use pdfString(val.RawString()) instead of val.String(). pdfString() in sign/helpers.go escapes \, (, ), \r and wraps in (...). RawString() gives the unescaped bytes, pdfString() re-escapes for valid PDF output.

Fixes #132

@vanbroup
Copy link
Copy Markdown
Member

vanbroup commented Apr 7, 2026

Please note that #126 is going te replace the current main branch when ready.

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.

createIncPageUpdate corrupts PDF string values with Go-style double quotes

2 participants