Skip to content

guard ctype calls against out-of-range wide characters - #234

Open
zayeem06 wants to merge 1 commit into
antlr:masterfrom
zayeem06:ctype-wide-char-range
Open

guard ctype calls against out-of-range wide characters#234
zayeem06 wants to merge 1 commit into
antlr:masterfrom
zayeem06:ctype-wide-char-range

Conversation

@zayeem06

@zayeem06 zayeem06 commented Jul 8, 2026

Copy link
Copy Markdown

Out-of-bounds ctype read on wide input characters

The C runtime passes UTF16/UTF32 code points straight into isprint()/isdigit(). On a lexer error displayRecognitionError calls isprint(ex->c), where ex->c is filled from is->_LA() on the char stream, so with a UTF16/UTF32 input stream it can be any code point up to 0x10FFFF. printableUTF16 and toInt32_UTF16 do the same on their UINT16 characters. The C standard only allows an argument representable as unsigned char or EOF, so anything above 255 reads past the ctype classification table.

I gated each call with a <= 255 range 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 in displayRecognitionError now falls through to the existing hex branch. Worth a look at whether keeping the wide char as-is rather than escaping it in printableUTF16 matches what you'd want there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant