Repository navigation
[rtext] Fix GetCodepoint() size on invalid sequences reading past the string end - #6348
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
3 of 4 tasks
This branch has not been deployed
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.
On an invalid or cut-off UTF-8 sequence,
GetCodepoint()reports a size that includes the byte that broke the sequence. When that byte is the string's'\0', a caller that steps by the size walks past the end:\xe2\x82returns'?'with size 3, sopjumps over the terminator. The same happens for a lone lead byte before'\0'(size 2) and for 4-byte sequences (size 4).The size is now the number of bytes before the one that broke the sequence, so the bad byte is read again as the start of the next character:
"\xe2\x82"gives one'?'of size 2 and stops at'\0'. Lead bytes that can't start a sequence here (E0followed by80-9F,ED A0-BFsurrogates,F0 80-8F,F4 90-BF) consume 1 byte. Valid input decodes as before.Tested by stepping through 5000 random strings built from valid, cut-off, surrogate, overlong and stray bytes and comparing the codepoints with Python's
bytes.decode("utf-8", "replace"), which follows the Unicode recommendation of one replacement per maximal invalid subpart:Builds with
PLATFORM_MEMORY.