Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex matching when using .*\b triggers ArrayIndexOutOfBoundsException #1537

Closed
brianstien opened this issue Feb 28, 2014 · 2 comments
Closed

Comments

@brianstien
Copy link

To reproduce run ruby -e '/foo.*\b/ =~ "foo"'

I was able to reproduce this error in JRuby 1.7.8, 1.7.10, and 1.7.11. It only occurs when the regex contains includes the pattern .*\b

@anba
Copy link

anba commented Mar 3, 2014

Applying the fix for f8ad5e2d63c6db61c5f88649ea30338eeaccae27 for the multibyte methods should resolve the AIOOBE issue. But apparently there is also another issue in the ANYCHAR_STAR operation when the end of input has been reached.
Output from Ruby 2.1.1 (or any other implementation based on Oniguruma):

irb(main):001:0> /A\b/ =~ "A"
=> 0
irb(main):002:0> /A.?\b/ =~ "A"
=> 0
irb(main):003:0> /A(.)*\b/ =~ "A"
=> 0
irb(main):004:0> /A.*\b/ =~ "A"
=> nil

IMO the last expression should also evaluate to 0 instead of nil.

ByteCodeMachine#opAnyCharStar() either needs to perform an early return and not update sprev when (s >= range) is true. Or it needs to push a stack entry for the current state when (s >= range) is true. Most likely the former, for example matching /A.*\>/ against "A" with the grep-syntax configuration triggers a different AIOOBE in ByteCodeMachine#opWordEnd().

To wrap things up, I'd say the underlying issue is in Oniguruma's ANYCHAR_STAR implementation, someone familiar with that code base should take a look.

anba added a commit to anba/es6draft that referenced this issue Mar 4, 2014
@kares
Copy link
Member

kares commented Apr 8, 2016

verified it works on 1.7.24 as well as 9.0.5.0

@kares kares closed this as completed Apr 8, 2016
@kares kares added this to the Invalid or Duplicate milestone Apr 8, 2016
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

No branches or pull requests

3 participants