Reject non-ASCII digit look-alikes in AsciiEncoding SWAR fast paths - #367
Open
raphaelroshan wants to merge 1 commit into
Open
Reject non-ASCII digit look-alikes in AsciiEncoding SWAR fast paths#367raphaelroshan wants to merge 1 commit into
raphaelroshan wants to merge 1 commit into
Conversation
…paths Follow-up to aeron-io#366, which fixed the scalar tail loops but noted the SIMD fast paths were unaffected. readFourBytesLittleEndian/readEightBytesLittleEndian pack each char into a byte lane via a left shift, so a non-ASCII char in the top lane (e.g. U+0130, low byte 0x30) has its high byte shifted out of the word and is accepted as a digit -- parseIntAscii("123İ", 0, 4) returned 1230 instead of throwing. OR the chars and reject the window if any exceeds 0xFF, reusing the already-loaded chars (no extra reads).
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.
Follow-up to #366. That PR fixed the scalar tail loops of the
CharSequenceinteger parsers but noted the SIMD (SWAR) fast paths were unaffected — this closes that gap.readFourBytesLittleEndian/readEightBytesLittleEndianpack eachcharinto a byte lane with a left shift. A non-ASCII char in the top lane (e.g.İ= U+0130, low byte0x30) has its high byte shifted out of the 32-/64-bit word, so only the digit-looking low byte survives andisFourDigitsAsciiEncodedNumberaccepts it:(A look-alike in a non-top lane already corrupts an adjacent byte and is correctly rejected — only the top lane leaks.)
Fix: OR the chars in each reader and, if any exceeds
0xFF, force the digit check to fail. This reuses the chars already loaded, so there are no extra reads on the fast path. ExtendedshouldRejectNonAsciiCharsWhoseLowByteLooksLikeADigitwith top-lane cases for the 4- and 8-char windows (they fail before this change, pass after).