encoding/utf8: enforce scalar and buffer bounds
This commit is contained in:
@@ -20,7 +20,7 @@ import encoding.utf8;
|
||||
};
|
||||
|
||||
// ref/hare/encoding/utf8/rune.ha:15. ASCII → 1; legal multibyte
|
||||
// leads → 2/3/4; continuation and >0xF7 → invalid.
|
||||
// leads → 2/3/4; continuation and >0xF4 → invalid.
|
||||
|
||||
@test fn utf8sz_classify() void = {
|
||||
match (utf8.utf8sz(0u8)) {
|
||||
@@ -51,7 +51,19 @@ import encoding.utf8;
|
||||
case let n: i32 => { assert(!(n != 4)); };
|
||||
case let e: utf8.invalid => { abort(); };
|
||||
};
|
||||
match (utf8.utf8sz(0xF8u8)) { // 5-byte lead — illegal in modern UTF-8
|
||||
match (utf8.utf8sz(0xF4u8)) { // U+10FFFF may begin with F4
|
||||
case let n: i32 => { assert(!(n != 4)); };
|
||||
case let e: utf8.invalid => { abort(); };
|
||||
};
|
||||
match (utf8.utf8sz(0xF5u8)) { // above Unicode's scalar range
|
||||
case let n: i32 => { abort(); };
|
||||
case let e: utf8.invalid => void;
|
||||
};
|
||||
match (utf8.utf8sz(0xF6u8)) {
|
||||
case let n: i32 => { abort(); };
|
||||
case let e: utf8.invalid => void;
|
||||
};
|
||||
match (utf8.utf8sz(0xF7u8)) {
|
||||
case let n: i32 => { abort(); };
|
||||
case let e: utf8.invalid => void;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user