Skip to content

fix: handle corrupted signature data - #5916

Merged
vitormattos merged 3 commits into
mainfrom
fix/handle-corrupted-signature-data
Dec 2, 2025
Merged

vitormattos merged 3 commits into
mainfrom
fix/handle-corrupted-signature-data

Conversation

@vitormattos

Copy link
Copy Markdown
Member

No description provided.

When processing PDF signatures, hex2bin() and stream_get_contents()
can fail and return false when dealing with corrupted or malformed
signature data. Previously, this would cause a TypeError when false
was passed to processSignature() which expects ?string.

Now, invalid signatures are properly reported to users with a
'Digest Mismatch' validation error instead of causing a fatal error.

This fix:
- Validates hex2bin() return value before yielding
- Validates stream_get_contents() return value before processing
- Returns null for corrupted signatures which are then reported as invalid
- Suppresses expected hex2bin() warnings for non-hexadecimal data

Fixes the issue reported where users encountered:
TypeError: Argument #2 ($signature) must be of type ?string, false given

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Add test case to verify that PDFs with corrupted signature data
(invalid hexadecimal strings) are properly handled and reported
to users with appropriate validation errors instead of throwing
exceptions.

The test verifies:
- Corrupted signatures return validation error
- Error has correct structure with id and label
- Error is identified as 'Digest mismatch' (id: 3)
- No fatal errors or exceptions are thrown

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos vitormattos added this to the Next Major (33) milestone Dec 2, 2025
@vitormattos vitormattos self-assigned this Dec 2, 2025
@github-project-automation github-project-automation Bot moved this to 0. Needs triage in LibreSign Roadmap Dec 2, 2025
@vitormattos

Copy link
Copy Markdown
Member Author

/backport to stable32

@vitormattos

Copy link
Copy Markdown
Member Author

/backport to stable31

@backportbot-libresign backportbot-libresign Bot added the backport-request Request to backport a change to supported stable branches label Dec 2, 2025
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos
vitormattos merged commit 9adaada into main Dec 2, 2025
65 checks passed
@vitormattos
vitormattos deleted the fix/handle-corrupted-signature-data branch December 2, 2025 13:58
@github-project-automation github-project-automation Bot moved this from 0. Needs triage to 4. to release in LibreSign Roadmap Dec 2, 2025
@backportbot-libresign backportbot-libresign Bot removed the backport-request Request to backport a change to supported stable branches label Dec 2, 2025
@vitormattos
vitormattos restored the fix/handle-corrupted-signature-data branch December 2, 2025 14:00
@vitormattos
vitormattos deleted the fix/handle-corrupted-signature-data branch December 11, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant