Skip to content

fix: reset SignContext state on SignPDF retry to prevent XRef corruption#136

Open
ryanmiura wants to merge 1 commit into
digitorus:mainfrom
ryanmiura:ryanmiura/fix/sign-state-pollution
Open

fix: reset SignContext state on SignPDF retry to prevent XRef corruption#136
ryanmiura wants to merge 1 commit into
digitorus:mainfrom
ryanmiura:ryanmiura/fix/sign-state-pollution

Conversation

@ryanmiura
Copy link
Copy Markdown

@ryanmiura ryanmiura commented Apr 13, 2026

Summary

This PR fixes a bug where retrying a PDF signature (due to buffer size increase) results in a corrupted XRef table.

Changes

I've added a reset of the following fields at the beginning of the SignPDF() method in sign.go:

  • context.newXrefEntries
  • context.updatedXrefEntries
  • context.lastXrefID

By resetting these fields to nil or 0 at the start of the process, we ensure that any partial work performed during a failed signing attempt (where the signature was too long) does not pollute the cross-reference table of the successful attempt.

Testing

Tested with incremental signatures and large visual appearances. The resulting PDFs are now structurally valid and can be parsed correctly by digitorus/pdf and other PDF readers without panics.

Fixes #135

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.

State pollution in SignContext during signature retry leads to corrupted XRef table

1 participant