Skip to content

Reject non-ASCII digit look-alikes in AsciiEncoding SWAR fast paths - #367

Open
raphaelroshan wants to merge 1 commit into
aeron-io:masterfrom
raphaelroshan:fix/ascii-encoding-swar-nonascii
Open

Reject non-ASCII digit look-alikes in AsciiEncoding SWAR fast paths#367
raphaelroshan wants to merge 1 commit into
aeron-io:masterfrom
raphaelroshan:fix/ascii-encoding-swar-nonascii

Conversation

@raphaelroshan

Copy link
Copy Markdown
Contributor

Follow-up to #366. That PR fixed the scalar tail loops of the CharSequence integer parsers but noted the SIMD (SWAR) fast paths were unaffected — this closes that gap.

readFourBytesLittleEndian/readEightBytesLittleEndian pack each char into a byte lane with a left shift. A non-ASCII char in the top lane (e.g. İ = U+0130, low byte 0x30) has its high byte shifted out of the 32-/64-bit word, so only the digit-looking low byte survives and isFourDigitsAsciiEncodedNumber accepts it:

AsciiEncoding.parseIntAscii("123İ", 0, 4);      // returned 1230 instead of throwing
AsciiEncoding.parseLongAscii("1234567İ", 0, 8); // returned 12345670 instead of throwing

(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. Extended shouldRejectNonAsciiCharsWhoseLowByteLooksLikeADigit with top-lane cases for the 4- and 8-char windows (they fail before this change, pass after).

…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).
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.

1 participant