mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
scanner: guard against scanner panic, discovered by fuzzing in PR#22016
This commit is contained in:
parent
c0bb9605c0
commit
793b66d8d5
1 changed files with 8 additions and 0 deletions
|
@ -1445,6 +1445,10 @@ fn (mut s Scanner) decode_o_escapes(sinput string, start int, escapes_pos []int)
|
|||
|
||||
fn (mut s Scanner) decode_u16_escape_single(str string, idx int) (int, string) {
|
||||
end_idx := idx + 6 // "\uXXXX".len == 6
|
||||
if idx + 2 > str.len || end_idx > str.len {
|
||||
s.error_with_pos('unfinished u16 escape started at', s.current_pos())
|
||||
return 0, ''
|
||||
}
|
||||
escaped_code_point := strconv.parse_uint(str[idx + 2..end_idx], 16, 32) or { 0 }
|
||||
// Check if Escaped Code Point is invalid or not
|
||||
if rune(escaped_code_point).length_in_bytes() == -1 {
|
||||
|
@ -1468,6 +1472,10 @@ fn (mut s Scanner) decode_u16erune(str string) string {
|
|||
|
||||
fn (mut s Scanner) decode_u32_escape_single(str string, idx int) (int, string) {
|
||||
end_idx := idx + 10 // "\uXXXXXXXX".len == 10
|
||||
if idx + 2 > str.len || end_idx > str.len {
|
||||
s.error_with_pos('unfinished u32 escape started at', s.current_pos())
|
||||
return 0, ''
|
||||
}
|
||||
escaped_code_point := strconv.parse_uint(str[idx + 2..end_idx], 16, 32) or { 0 }
|
||||
// Check if Escaped Code Point is invalid or not
|
||||
if rune(escaped_code_point).length_in_bytes() == -1 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue