Skip to content

test: prove Modified UTF-8 overlong NUL (0xC0 0x80) is rejected as OK…#42

Merged
ionux merged 1 commit intomainfrom
claude/fix-utf8-null-byte-e0ve1
Mar 12, 2026
Merged

test: prove Modified UTF-8 overlong NUL (0xC0 0x80) is rejected as OK…#42
ionux merged 1 commit intomainfrom
claude/fix-utf8-null-byte-e0ve1

Conversation

@ionux
Copy link
Copy Markdown
Owner

@ionux ionux commented Mar 12, 2026

…J_ERROR_BAD_STRING

Add test_utf8_overlong_nul_c0_80 which mathematically proves that the two-byte sequence 0xC0 0x80 — the "Modified UTF-8" overlong encoding of U+0000 — is caught by okj_validate_utf8_sequence and causes okj_parse to return OKJ_ERROR_BAD_STRING rather than accepting the sequence as valid or treating it as a premature string terminator.

Proof embedded in the test comment:
b0 = 0xC0 (192)
ASCII gate: 0xC0 <= 0x7F => 192 <= 127 => FALSE
2-byte gate: 0xC0 >= 0xC2 => 192 >= 194 => FALSE
(0xC0 and 0xC1 are deliberately excluded from [0xC2, 0xDF] per RFC 3629 §3)
All remaining branch predicates also fail for b0 = 0xC0.
Fall-through return 0U -> OKJ_ERROR_BAD_STRING.

https://claude.ai/code/session_01HHohyZBhqxpWqruAGoeDtZ

…J_ERROR_BAD_STRING

Add test_utf8_overlong_nul_c0_80 which mathematically proves that the
two-byte sequence 0xC0 0x80 — the "Modified UTF-8" overlong encoding of
U+0000 — is caught by okj_validate_utf8_sequence and causes okj_parse to
return OKJ_ERROR_BAD_STRING rather than accepting the sequence as valid or
treating it as a premature string terminator.

Proof embedded in the test comment:
  b0 = 0xC0 (192)
  ASCII gate:   0xC0 <= 0x7F  =>  192 <= 127  =>  FALSE
  2-byte gate:  0xC0 >= 0xC2  =>  192 >= 194  =>  FALSE
  (0xC0 and 0xC1 are deliberately excluded from [0xC2, 0xDF] per RFC 3629 §3)
  All remaining branch predicates also fail for b0 = 0xC0.
  Fall-through return 0U -> OKJ_ERROR_BAD_STRING.

https://claude.ai/code/session_01HHohyZBhqxpWqruAGoeDtZ
@ionux ionux merged commit c45c3d2 into main Mar 12, 2026
1 check passed
@ionux ionux deleted the claude/fix-utf8-null-byte-e0ve1 branch March 12, 2026 15:29
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.

2 participants