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

Fix unicode decode bug on surrogate error mode #5546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions 2 .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion 7 vm/src/codecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if p.len().overflowing_sub(range.start).0 >= byte_length {
if p.len() >= range.start + byte_length {

does this work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for confirming

match standard_encoding {
StandardEncoding::Utf8 => {
if (p[0] as u32 & 0xf0) == 0xe0
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.