Skip to content
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

Fix Bytes deserialization for unicode values #695

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

popzxc
Copy link
Contributor

@popzxc popzxc commented Jun 14, 2023

Current Bytes deserialization logic can panic if supplied non-ASCII values: it uses str::len and SliceIndex<str>, both of which are byte-based (not char-based).
The deserializer code can panic when [0..2] range is not on the char boundary.

This PR fixed it by checking whether the string is ASCII first.

Copy link
Owner

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Good catch! I proposed a change to maybe just use starts_with, can you check if it passes all the tests?

src/types/bytes.rs Outdated Show resolved Hide resolved
@popzxc popzxc force-pushed the fix-bytes-deserialization branch from f27ba1d to d05d283 Compare June 14, 2023 09:48
@tomusdrw tomusdrw merged commit d49ad4f into tomusdrw:master Jun 14, 2023
@popzxc popzxc deleted the fix-bytes-deserialization branch June 14, 2023 09:55
@popzxc
Copy link
Contributor Author

popzxc commented Jun 20, 2023

@tomusdrw I kind of need this fix for my project, could you please release a new version?

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.

2 participants