fix(core): correct continuation byte range in UTF-8 validator - #14972
Open
pritesh-4 wants to merge 1 commit into
Open
fix(core): correct continuation byte range in UTF-8 validator#14972pritesh-4 wants to merge 1 commit into
pritesh-4 wants to merge 1 commit into
Conversation
pritesh-4
force-pushed
the
fix/utf8-continuation-check
branch
from
September 6, 2026 18:20
3ac2670 to
2622b0c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This Pull Request fixes a typographical bug in kong.tools.string.validate_utf8 where the byte boundary range for 2-byte UTF-8 sequences was incorrectly defined.
Specifically, the continuation byte's lower limit was written as \123 (decimal 123, representing ASCII {) instead of the correct \128 (decimal 128, representing 0x80). This bug allowed invalid 2-byte sequences with trailing ASCII punctuation or control characters (123..127) to pass UTF-8 validation checks and be saved into database schemas.
Background & Technical Context
In Lua, escape sequences inside string literals (e.g. \ddd) are parsed as decimal values by default, unlike other programming languages where they are parsed as octals.
According to Table 3-7 of the Unicode Standard (referenced in the function comments), a valid 2-byte UTF-8 sequence consists of:
A lead byte in the range 0xC2..0xDF (decimal 194..223).
A continuation byte in the range 0x80..0xBF (decimal 128..191).
Due to a typo on
kong/tools/string.lua:L254:
elseif i == find(str, "[\194-\223][\123-\191]", i) then i = i + 2
The range was specified as [\123-\191]. This means any lead byte in the 194..223 range followed by any byte between 123 (ASCII {) and 191 (e.g., 123 ({), 124 (|), 125 (}), 126 (~), 127 (DEL)) was incorrectly validated as a valid 2-byte UTF-8 sequence.
Changes Made
Updated
kong/tools/string.lua
to adjust the 2-byte sequence validation pattern to use the correct \128 lower boundary.
Checklist
changelog/unreleased/kongorskip-changeloglabel added on PR if changelog is unnecessary. README.mdIssue reference
Fix #14971 _