Regexp match raises java.lang.ArrayIndexOutOfBoundsException in numbered backreference #3538

Closed
knu opened this Issue Dec 13, 2015 · 9 comments

Comments

Projects
None yet
3 participants
@knu
Contributor

knu commented Dec 13, 2015

Confirmed with JRuby 9.0.4.0 and 1.7.23.

% cat a.rb
/^\s*(\d+\.?\d*)\s*(?:;(?:\s*url\s*=\s*(['"]?)(\S*)\2)?\s*)?$/i.match("0; url=http://www.drphil.com")

# JRuby 9.0.4.0
% jruby -v a.rb
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit Server VM 23.3-b01 on 1.7.0_07-b10 +jit [darwin-x86_64]
Unhandled Java exception: java.lang.ArrayIndexOutOfBoundsException: 29
java.lang.ArrayIndexOutOfBoundsException: 29
               length at org/jcodings/specific/UTF8Encoding.java:35
         opBackRefNIC at org/joni/ByteCodeMachine.java:1294
              matchAt at org/joni/ByteCodeMachine.java:261
           matchCheck at org/joni/Matcher.java:304
  searchInterruptible at org/joni/Matcher.java:480
                  run at org/jruby/RubyRegexp.java:271
  executeBlockingTask at org/jruby/RubyThread.java:1337
        matcherSearch at org/jruby/RubyRegexp.java:233
             search19 at org/jruby/RubyRegexp.java:1129
             search19 at org/jruby/RubyRegexp.java:1084
             matchPos at org/jruby/RubyRegexp.java:1060
        match19Common at org/jruby/RubyRegexp.java:1028
            match_m19 at org/jruby/RubyRegexp.java:1014
                 call at org/jruby/internal/runtime/methods/JavaMethod.java:380
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:313
                 call at org/jruby/runtime/callsite/CachingCallSite.java:163
                <top> at a.rb:2
  invokeWithArguments at java/lang/invoke/MethodHandle.java:566
                 load at org/jruby/ir/Compiler.java:111
            runScript at org/jruby/Ruby.java:821
            runScript at org/jruby/Ruby.java:813
          runNormally at org/jruby/Ruby.java:751
          runFromMain at org/jruby/Ruby.java:573
        doRunFromMain at org/jruby/Main.java:409
          internalRun at org/jruby/Main.java:304
                  run at org/jruby/Main.java:233
                 main at org/jruby/Main.java:200

# JRuby 9.0.4.0
% jruby -v a.rb
jruby 1.7.23 (1.9.3p551) 2015-11-24 f496dd5 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_07-b10 +jit [darwin-x86_64]
USASCIIEncoding.java:33:in `length': java.lang.ArrayIndexOutOfBoundsException: 28
        from ByteCodeMachine.java:1285:in `opBackRefNIC'
        from ByteCodeMachine.java:261:in `matchAt'
        from Matcher.java:304:in `matchCheck'
        from Matcher.java:480:in `searchInterruptible'
        from RubyRegexp.java:273:in `run'
        from RubyThread.java:1066:in `executeBlockingTask'
        from RubyRegexp.java:235:in `matcherSearch'
        from RubyRegexp.java:1780:in `search19'
        from RubyRegexp.java:1720:in `matchPos'
        from RubyRegexp.java:1701:in `match19Common'
        from RubyRegexp.java:1680:in `match_m19'
        from RubyRegexp$INVOKER$i$match_m19.gen:-1:in `call'
        from JavaMethod.java:350:in `call'
        from CachingCallSite.java:326:in `cacheAndCall'
        from CachingCallSite.java:170:in `call'
        from a.rb:1:in `__file__'
        from a.rb:-1:in `load'
        from Ruby.java:857:in `runScript'
        from Ruby.java:850:in `runScript'
        from Ruby.java:729:in `runNormally'
        from Ruby.java:578:in `runFromMain'
        from Main.java:393:in `doRunFromMain'
        from Main.java:288:in `internalRun'
        from Main.java:217:in `run'
        from Main.java:197:in `main'
@lopex

This comment has been minimized.

Show comment
Hide comment
@lopex

lopex Dec 13, 2015

Member

reduced case:

"x" =~ /(x?)x*\1/i
Member

lopex commented Dec 13, 2015

reduced case:

"x" =~ /(x?)x*\1/i
@lopex

This comment has been minimized.

Show comment
Hide comment
@lopex

lopex Dec 13, 2015

Member

Fixed in cf9171576de0c7f8070b783569e3dc7d1656ef16

Member

lopex commented Dec 13, 2015

Fixed in cf9171576de0c7f8070b783569e3dc7d1656ef16

@knu

This comment has been minimized.

Show comment
Hide comment
@knu

knu Dec 14, 2015

Contributor

Thanks for minimizing the case, and where's the commit?

Contributor

knu commented Dec 14, 2015

Thanks for minimizing the case, and where's the commit?

@lopex

This comment has been minimized.

Show comment
Hide comment
@knu

This comment has been minimized.

Show comment
Hide comment
@knu

knu Dec 14, 2015

Contributor

OK, thanks. I don't know what to say about the //...

Contributor

knu commented Dec 14, 2015

OK, thanks. I don't know what to say about the //...

@lopex

This comment has been minimized.

Show comment
Hide comment
@lopex

lopex Dec 14, 2015

Member

Actually that comment was wrong, it should be compared against range

Member

lopex commented Dec 14, 2015

Actually that comment was wrong, it should be compared against range

@lopex

This comment has been minimized.

Show comment
Hide comment
@lopex

lopex Dec 14, 2015

Member

It appears that backref at level:

"x" =~ /(x?)x*\k<1+0>/i

and multiplex definition:

"x" =~ /(?<n>x?)(?<n>x?)\k<n>/i

were also affected, fixed in jruby/joni@2d4580d

Member

lopex commented Dec 14, 2015

It appears that backref at level:

"x" =~ /(x?)x*\k<1+0>/i

and multiplex definition:

"x" =~ /(?<n>x?)(?<n>x?)\k<n>/i

were also affected, fixed in jruby/joni@2d4580d

@lopex

This comment has been minimized.

Show comment
Hide comment
@lopex

lopex Dec 14, 2015

Member

Leaving the issue open for jruby release cycle...

Member

lopex commented Dec 14, 2015

Leaving the issue open for jruby release cycle...

@knu

This comment has been minimized.

Show comment
Hide comment
@knu

knu Jan 21, 2016

Contributor

Just confirmed JRuby 1.7.24 (with Joni 2.1.9 bundled) fixes the issue. Thanks!
Looking forward to a new release of JRuby 9000.

Contributor

knu commented Jan 21, 2016

Just confirmed JRuby 1.7.24 (with Joni 2.1.9 bundled) fixes the issue. Thanks!
Looking forward to a new release of JRuby 9000.

@kares kares added this to the JRuby 9.0.5.0 milestone Jan 21, 2016

@kares kares closed this Jan 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment