Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 800b6ba

Browse filesBrowse 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
Copy full SHA for 800b6ba

File tree

1 file changed

+6
-1
lines changed
Filter options

1 file changed

+6
-1
lines changed

‎vm/src/codecs.rs

Copy file name to clipboardExpand all lines: vm/src/codecs.rs
+6-1
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.