-
Notifications
You must be signed in to change notification settings - Fork 180
Add utf-8 validation for input source #2374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,8 @@ class Lexer | |
Lexer (Lexer &&other) = default; | ||
Lexer &operator= (Lexer &&other) = default; | ||
|
||
bool input_source_is_valid_utf8 (); | ||
|
||
// Returns token n tokens ahead of current position. | ||
const_TokenPtr peek_token (int n) { return token_queue.peek (n); } | ||
// Peeks the current token. | ||
|
@@ -217,9 +219,9 @@ class Lexer | |
|
||
Codepoint next_codepoint () | ||
{ | ||
uint8_t input = next_byte (); | ||
uint32_t input = next_byte (); | ||
|
||
if ((int8_t) input == EOF) | ||
if ((int32_t) input == EOF) | ||
return Codepoint::eof (); | ||
else if (input < 128) | ||
{ | ||
|
@@ -246,11 +248,13 @@ class Lexer | |
// 3 bytes or UTF-8 BOM | ||
uint8_t input2 = next_byte (); | ||
// If the second byte is equal to 0xBB then the input is no longer a | ||
// valid UTF-8 char. | ||
// valid UTF-8 char. Then, we check if the third byte makes up a UTF | ||
// BOM. | ||
if (input == 0xEF && input2 == 0xBB) | ||
{ | ||
uint8_t input3 = next_byte (); | ||
if (input3 == 0xBF) | ||
// found BOM | ||
return next_codepoint (); | ||
else | ||
return {0xFFFE}; | ||
|
@@ -289,8 +293,6 @@ class Lexer | |
} | ||
else | ||
{ | ||
// rust_error_at (get_current_location (), | ||
// "invalid UTF-8 [SECND] (too long)"); | ||
return {0xFFFE}; | ||
} | ||
} | ||
|
@@ -362,8 +364,7 @@ class Lexer | |
{ | ||
if (offs >= buffer.size ()) | ||
return EOF; | ||
|
||
return buffer.at (offs++); | ||
return (uint8_t) buffer.at (offs++); | ||
} | ||
Comment on lines
364
to
368
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added casting to prevend bytes whose MSB is 1 from being sign-extended. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bugfix too |
||
|
||
public: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// { dg-excess-errors "stream did not contain valid UTF-8" } | ||
� | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contains a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not ÿ ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
input
fromuint8_t
touint32_t
so as to differentiate0xff
and EOF.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a bugfix