10000 Fix unicode decode bug on surrogate error mode by arihant2math · Pull Request #5546 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

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

Conversation

arihant2math
Copy link
Collaborator
@arihant2math arihant2math commented Feb 23, 2025

Fixes #5542; error introduced by #5502. Adds some debug assertions that are also in cpython.
This will help allow test_argparse to work for windows.

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
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?

8000

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

@youknowone youknowone merged commit 429754f into RustPython:main Feb 23, 2025
22 checks passed
78D1
@arihant2math arihant2math deleted the codecs-fix branch February 25, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bytes.decode doesn't honor error mode
2 participants
0