Repository: RustPython/RustPython (language: rust)

Issue:
Panic in codecs.rs
Windows x86-64 debug build with default features when running `cargo run -- -m test`.

```
thread 'main' panicked at vm\src\codecs.rs:626:12:
attempt to subtract with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\rustpython.exe -m test` (exit code: 101)
```


Discussion / hints:

Fix patch:
diff --git a/vm/src/codecs.rs b/vm/src/codecs.rs
index ff7bc48915..61be9f9176 100644
--- a/vm/src/codecs.rs
+++ b/vm/src/codecs.rs
@@ -623,7 +623,7 @@ fn surrogatepass_errors(err: PyObjectRef, vm: &VirtualMachine) -> PyResult<(PyOb
         // 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() - range.start >= byte_length {
+        if p.len().saturating_sub(range.start) >= byte_length {
             match standard_encoding {
                 StandardEncoding::Utf8 => {
                     if (p[0] as u32 & 0xf0) == 0xe0


Test patch: