From 8b31735ce2cadd1448d6666bb75b63a57ffb93fd Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Sat, 22 Feb 2025 17:46:53 -0800 Subject: [PATCH 1/2] subtract with overflow to check for whether to use surrogate Signed-off-by: Ashwin Naren --- vm/src/codecs.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/src/codecs.rs b/vm/src/codecs.rs index 898198f3d3..767bd873b6 100644 --- a/vm/src/codecs.rs +++ b/vm/src/codecs.rs @@ -619,11 +619,16 @@ fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyOb // Not supported, fail with original exception return Err(err.downcast().unwrap()); } + + debug_assert!(range.start <= 0.max(s.len() - 1)); + debug_assert!(range.end >= 1.min(s.len())); + debug_assert!(range.end <= s.len()); + let mut c: u32 = 0; // Try decoding a single surrogate character. If there are more, // let the codec call us again. let p = &s.as_bytes()[range.start..]; - if p.len().saturating_sub(range.start) >= byte_length { + if p.len().overflowing_sub(range.start).0 >= byte_length { match standard_encoding { StandardEncoding::Utf8 => { if (p[0] as u32 & 0xf0) == 0xe0 From 7801e2b63d277d887618d45d2334b52648303628 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Sat, 22 Feb 2025 17:54:13 -0800 Subject: [PATCH 2/2] enable test_argparse for windows on ci Signed-off-by: Ashwin Naren --- .github/workflows/ci.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3d1d32d12d..1eeecbd2a7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,7 +17,6 @@ concurrency: env: CARGO_ARGS: --no-default-features --features stdlib,zlib,importlib,encodings,sqlite,ssl # Skip additional tests on Windows. They are checked on Linux and MacOS. - # test_argparse: UnicodeDecodeError # test_glob: many failing tests # test_io: many failing tests # test_os: many failing tests @@ -26,7 +25,6 @@ env: # test_unicode: AttributeError: module '_winapi' has no attribute 'GetACP' # test_venv: couple of failing tests WINDOWS_SKIPS: >- - test_argparse test_glob test_io test_os