Skip to content

Conversation

@headius
Copy link
Contributor

@headius headius commented Dec 12, 2024

This is a re-port of the C code from @byroot for fast base 10 and base 16 integer scanning.

In #125, @kou pointed out there's an intermittent failure in the JRuby extension. We were unable to confirm exactly the circumstances that cause that failure, but this re-port should at least help reduce the change it is a bug in the original Java code.

This may help prevent ArrayIndexOutOfBounds randomly seen in CI.

See ruby#125
* Parse base should be from current pointer so add that to the get
  calls.
* Pull out ascii check into util method.
* Rename curr local var to ptr to better match C version.
This is to align the base10 code with the freshly-ported base16
code.

See ruby#125
@headius
Copy link
Contributor Author

headius commented Dec 12, 2024

@kou @byroot this should be ready to go but I have one concern about the C code...

It doesn't seem to update curr after the parse? I have that in the Java code because it seemed necessary.

This is temporary until we're sure that the AIOOB from
ruby#125 has been fixed by ruby#127.
@byroot
Copy link
Member

byroot commented Dec 12, 2024

It doesn't seem to update curr after the parse?

It does inside strscan_parse_integer

@headius
Copy link
Contributor Author

headius commented Dec 12, 2024

It does inside strscan_parse_integer

Aha, so it does! I will tweak this to move the final integer parse and curr update into a similar method, so it aligns better with the C code.

This aligns with C code that does the final parse and curr update
in strscan_parse_integer.
@kou kou merged commit ea0786b into ruby:master Dec 13, 2024
37 checks passed
@kou
Copy link
Member

kou commented Dec 13, 2024

Thanks!

kou pushed a commit that referenced this pull request May 3, 2025
Fix GH-152

CRuby can walk off the end because there's always a null byte. In JRuby,
the byte array is often (usually?) the exact size of the string. So we
need to check if len++ walked off the end.

This code was ported from a version by @byroot in
#127 but I missed adding this check
due to a lack of tests. A test is included for both "-" and "+" parsing.
matzbot pushed a commit to ruby/ruby that referenced this pull request May 8, 2025
(ruby/strscan#153)

Fix ruby/strscan#152

CRuby can walk off the end because there's always a null byte. In JRuby,
the byte array is often (usually?) the exact size of the string. So we
need to check if len++ walked off the end.

This code was ported from a version by @byroot in
ruby/strscan#127 but I missed adding this check
due to a lack of tests. A test is included for both "-" and "+" parsing.

ruby/strscan@1abe4ca556
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.

3 participants