Use UTF-8 safe char8_t type when iterating over encode string input#2575
Open
s77rt wants to merge 2 commits intoExpensify:mainfrom
Open
Use UTF-8 safe char8_t type when iterating over encode string input#2575s77rt wants to merge 2 commits intoExpensify:mainfrom
char8_t type when iterating over encode string input#2575s77rt wants to merge 2 commits intoExpensify:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
When encoding a string, we iterate over each byte as
charandcharsign is platform dependent, on arm it's unsigned and on x64 it's signed. When this is signed, non-ASCII characters e.g.āor11000100 10000001bytes in UTF-8 are seen as-60and-127and after bit-shifting we get-4and-8. These are used as indexes to accesshexCharsand since they are negative and out-of-bound this causes UB.This PR changes that we treat the bytes as
char8_twhich is guaranteed to be unsigned.Fixed Issues
Fixes https://github.com/Expensify/Expensify/issues/617781
Tests
LibStuff::testEncodeDecodeURIComponent