8000 subtract with overflow to check for whether to use surrogate · RustPython/RustPython@800b6ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 800b6ba

Browse files
committed
subtract with overflow to check for whether to use surrogate
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 23236aa commit 800b6ba

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

vm/src/codecs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,16 @@ fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyOb
619619
// Not supported, fail with original exception
620620
return Err(err.downcast().unwrap());
621621
}
622+
623+
debug_assert!(range.start <= 0.max(s.len() - 1));
624+
debug_assert!(range.end >= 1.min(s.len()));
625+
debug_assert!(range.end <= s.len());
626+
622627
let mut c: u32 = 0;
623628
// Try decoding a single surrogate character. If there are more,
624629
// let the codec call us again.
625630
let p = &s.as_bytes()[range.start..];
626-
if p.len().saturating_sub(range.start) >= byte_length {
631+
if p.len().overflowing_sub(range.start).0 >= byte_length {
627632
match standard_encoding {
628633
StandardEncoding::Utf8 => {
629634
if (p[0] as u32 & 0xf0) == 0xe0

0 commit comments

Comments
 (0)
0