Skip to content

fix(tools): correct continuation byte range in validate_utf8 - #15038

Open
Sayandevxyz wants to merge 1 commit into
Kong:masterfrom
Sayandevxyz:fix/validate-utf8-continuation-byte
Open

Sayandevxyz wants to merge 1 commit into
Kong:masterfrom
Sayandevxyz:fix/validate-utf8-continuation-byte

Conversation

@Sayandevxyz

Copy link
Copy Markdown

Summary

Fixes a typographical error in validate_utf8 where 2-byte UTF-8 sequences accepted ASCII characters in the range 123..127 ({, |, }, ~, DEL) as valid continuation bytes.

Problem

According to Table 3-7 of the Unicode Standard, valid 2-byte UTF-8 sequences consist of a leading byte in 0xC2..0xDF (decimal 194..223) followed by a continuation byte in 0x80..0xBF (decimal 128..191).

In kong/tools/string.lua, line 254 defined the range using [\123-\191]:

elseif i == find(str, "[\194-\223][\123-\191]", i) then i = i + 2

Table 3-7 of the Unicode Standard defines the continuation byte range
for 2-byte UTF-8 sequences as 0x80..0xBF (decimal 128..191). The pattern
previously used \123 (ASCII '{'), allowing invalid sequences with second
bytes between 123 and 127 to pass validation.

Change the continuation range from [\123-\191] to [\128-\191] to strictly
enforce valid UTF-8 sequences, and add unit test coverage for the boundary
values.

Fixes Kong#14971

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant