Skip to content

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

@knu

Description

@knu

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'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions