[ruby/strscan] jruby: Check if len++ walked off the end

(https://github.com/ruby/strscan/pull/153)

Fix https://github.com/ruby/strscan/pull/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
https://github.com/ruby/strscan/pull/127 but I missed adding this check
due to a lack of tests. A test is included for both "-" and "+" parsing.

https://github.com/ruby/strscan/commit/1abe4ca556
This commit is contained in:
Charles Oliver Nutter 2025-05-02 23:26:05 -05:00 committed by Hiroshi SHIBATA
parent 5a0306f9c1
commit 8685a81e6a
No known key found for this signature in database
GPG Key ID: F9CF13417264FAC2

View File

@ -1001,6 +1001,16 @@ module StringScannerTests
assert_equal(0, s.pos)
refute_predicate(s, :matched?)
s = create_string_scanner('-')
assert_nil(s.scan_integer)
assert_equal(0, s.pos)
refute_predicate(s, :matched?)
s = create_string_scanner('+')
assert_nil(s.scan_integer)
assert_equal(0, s.pos)
refute_predicate(s, :matched?)
huge_integer = '1' * 2_000
s = create_string_scanner(huge_integer)
assert_equal(huge_integer.to_i, s.scan_integer)