Skip to content

[stable32] fix: handle corrupted signature data - #5918

Merged
vitormattos merged 3 commits into
stable32from
backport/5916/stable32
Dec 2, 2025
Merged

vitormattos merged 3 commits into
stable32from
backport/5916/stable32

Conversation

@backportbot-libresign

Copy link
Copy Markdown

Backport of PR #5916

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>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@github-project-automation github-project-automation Bot moved this to 0. Needs triage in LibreSign Roadmap Dec 2, 2025
@backportbot-libresign backportbot-libresign Bot added this to the Next Patch (32) milestone Dec 2, 2025
@vitormattos
vitormattos merged commit 22db0ea into stable32 Dec 2, 2025
62 checks passed
@vitormattos
vitormattos deleted the backport/5916/stable32 branch December 2, 2025 14:23
@github-project-automation github-project-automation Bot moved this from 0. Needs triage to 4. to release in LibreSign Roadmap Dec 2, 2025
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