Skip to content

der: test invalid UTF8 leading continuation bytes directly - #817

Merged
karel-m merged 1 commit into
libtom:developfrom
hakarrr:libtom561-utf8-regression
Nov 17, 2026
Merged

karel-m merged 1 commit into
libtom:developfrom
hakarrr:libtom561-utf8-regression

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Fixes: #561

The existing #507 flexi-parser vector still reports an error when the UTF8 fix is removed, because parsing fails later for an unrelated reason. Add a direct der_decode_utf8_string() regression so that failure cannot hide acceptance of an invalid leading continuation byte.

The test checks all leading bytes from 0x80 through 0xbf, each followed by another continuation byte, and also checks the original bf bf UTF8 payload. The DER length and output buffer are sufficient for the old decoder to accept the pair, so the expected CRYPT_INVALID_PACKET tests the invalid leading byte rather than truncation or output capacity. The existing flexi-parser vector stays unchanged. No production code changes.

Validation on Linux with LibTomMath:

  • Native -Werror full suite: 30 passed, 0 failed, 1 nop.
  • ASan + UBSan full suite with leak detection: 30 passed, 0 failed, 1 nop; no sanitizer findings. The linked LibTomMath static library was not sanitizer-instrumented.
  • Mutation check: manually removing the two UTF8 guards shown in test for issue #507 always passes #561 leaves the old DER suite green, but fails the new test at the first continuation-byte assertion. Restoring the decoder makes it pass.

This adds coverage for the UTF8 portion of #507. It does not change the flexi-parser underflow handling discussed in #561.

Checklist

  • tests are added or updated
  • added a Fixes: tag to the commit message

Exercise UTF8 continuation bytes directly instead of depending on a later flexi-parser error.

Fixes: #561

Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer review this direct DER regression coverage for invalid UTF-8 leading continuation bytes? Please let me know if the cases need changing or if anything else is needed before it can move forward. Thanks.

@hakarrr

hakarrr commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Following up again on this contribution. If a maintainer could review when convenient, or point me at what to improve, I'd be grateful. Thanks for your time.

@karel-m

karel-m commented Nov 17, 2026

Copy link
Copy Markdown
Member

the added test is correct, merging now

but claim Fixes: #561 isn't accurate as #561 has two parts:

@karel-m
karel-m merged commit 78bd044 into libtom:develop Nov 17, 2026
1 check passed
@hakarrr

hakarrr commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the merge. Agreed - the Fixes tag was broader than this change. The PR only addresses the first part of #561: the #507 vector passing without the UTF8 fix. The flexi decoder length handling @jamuir described is untouched.

Since the merge auto-closed #561, that remaining part no longer has an open issue tracking it. Would you rather reopen #561, or should I open a focused issue for the der_decode_sequence_flexi.c underflow check so it stays tracked?

@karel-m

karel-m commented Nov 17, 2026

Copy link
Copy Markdown
Member

I have tried to fix remaining pieces from #561 in #822

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.

test for issue #507 always passes

2 participants