guard ctype calls against out-of-range wide characters - #234
Open
zayeem06 wants to merge 1 commit into
Open
Conversation
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.
Out-of-bounds ctype read on wide input characters
The C runtime passes UTF16/UTF32 code points straight into
isprint()/isdigit(). On a lexer errordisplayRecognitionErrorcallsisprint(ex->c), whereex->cis filled fromis->_LA()on the char stream, so with a UTF16/UTF32 input stream it can be any code point up to 0x10FFFF.printableUTF16andtoInt32_UTF16do the same on their UINT16 characters. The C standard only allows an argument representable asunsigned charor EOF, so anything above 255 reads past the ctype classification table.I gated each call with a
<= 255range check so wide characters skip the classification instead of indexing out of bounds. In-range bytes keep the exact same path, and a wide char indisplayRecognitionErrornow falls through to the existing hex branch. Worth a look at whether keeping the wide char as-is rather than escaping it inprintableUTF16matches what you'd want there.