Fix wrong bitmask and other utf8 validation bugs - #57
Merged
biljazovic merged 4 commits intoAug 11, 2026
Conversation
added 4 commits
August 8, 2026 01:25
…uation bytes validate_mqtt_utf8_char uses (c & 0xFE) == 0xFE to detect unicode noncharacters. That rejects any where low byte is 0xFE or 0xFF (e.g. U+00FE, U+00FF, U+1F5FE). It should reject the 34 non-characters. pop_front_unichar also never validates continuation bytes. That means malformed sequences like "\xC3z" are considered valid. These test currently fail and show both defects.
validate_mqtt_utf8_char only looked at the low byte for 0xFE or 0xFF instead of checking all the bits it needed to. Correct check is (c & 0xFFFE) == 0xFFFE. pop_front_unichar now checks the extra bytes are actually in range 0x80-0xBF before using them. Bad utf8 like "\xC3z" gets rejected now instead of decoded. Also fixed the 4-byte lead byte mask from 0x1F to 0x07 since only 3 bits are used there. Tests from the last commit pass now.
Two of these already pass since the last fix. The three overlong ones don't, since nothing checks for that yet.
pop_front_unichar decoded multi-byte sequences without checking the result was big enough to actually need that many bytes. So something like a 2-byte encoding of a plain ascii letter got accepted. Now it checks the decoded value against the minimum for each length (0x80, 0x800, 0x10000) and rejects it if too small.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #57 +/- ##
===========================================
+ Coverage 96.24% 96.46% +0.21%
===========================================
Files 44 44
Lines 3250 3280 +30
===========================================
+ Hits 3128 3164 +36
+ Misses 122 116 -6
🚀 New features to boost your workflow:
|
Collaborator
|
Thanks so much for the PR! Looks good to me. Unfortunately, 1.92 release is closed for all changes, so this will land in Boost 1.93 in December. |
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.
validate_mqtt_utf8_char only looked at the low byte for 0xFE or 0xFF instead of
checking all the bits it needed to. Correct check is (c & 0xFFFE) == 0xFFFE. This
was rejecting normal characters like þ (U+00FE) and even some emoji, not just the
handful of reserved code points it was supposed to catch.
pop_front_unichar also decoded multi-byte characters without checking the extra
bytes were actually in range 0x80-0xBF, and without checking the result was big
enough to need that many bytes. So bad utf8 like "\xC3z" got decoded instead of
rejected, and a 2-byte encoding of a plain ascii letter got accepted too. Both are
fixed now, along with the 4-byte lead byte mask which was 0x1F instead of 0x07.
Commits go test, fix, test, fix. Each test commit fails on its own and passes once
the fix commit right after it lands.