Description
When a signature exceeds the initial buffer size (SignatureMaxLengthBase), the library logs "Signature too long, retrying with increased buffer size" and recursively calls context.SignPDF().
However, the SignContext state is not fully reset between these attempts. Specifically, context.newXrefEntries, context.updatedXrefEntries, and context.lastXrefID retain their values from the failed first attempt. This results in:
- Duplicate XRef entries appended to the PDF.
- Incorrect offsets for subsequent objects.
- Panics when attempting to read the signed PDF (e.g., panic: loading {ID 0}: found float64 instead of objdef).
Steps to Reproduce
- Generate a digital signature using a large certificate chain or a visual signature with a large image payload that causes the signature to exceed the initial hex buffer.
- Observe the console log: "Signature too long, retrying with increased buffer size".
- Try to parse the resulting signed PDF back into the digitorus/pdf reader (e.g., attempting a second incremental signature).
Expected Behavior
The SignPDF or recursive caller method should always start with a clean state (empty XRef slices/zero IDs), avoiding XRef byte-offset corruption.
Description
When a signature exceeds the initial buffer size (SignatureMaxLengthBase), the library logs "Signature too long, retrying with increased buffer size" and recursively calls context.SignPDF().
However, the SignContext state is not fully reset between these attempts. Specifically, context.newXrefEntries, context.updatedXrefEntries, and context.lastXrefID retain their values from the failed first attempt. This results in:
Steps to Reproduce
Expected Behavior
The SignPDF or recursive caller method should always start with a clean state (empty XRef slices/zero IDs), avoiding XRef byte-offset corruption.