Skip to content

JRuby ext overflows slicing strings with non-zero begin #86

Closed

Description

@headius

When the string provided to StringScanner.new is represented by a ByteList with a non-zero begin offset, the length for new strings is calculated incorrectly (length and begin get added together). No tests exist for this case, which typically happens when the source string has itself been sliced off the end of a larger string and still shares the same buffer.

$ jruby -rstrscan -e 'str = "hellohello"[5..-1]; StringScanner.new(str).scan(/hello/)'
Unhandled Java exception: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 15 out of bounds for byte[10]
java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 15 out of bounds for byte[10]
            arraycopy at java/lang/System.java:-2
               <init> at org/jruby/util/ByteList.java:227
            newString at org/jruby/ext/strscan/RubyStringScanner.java:877
        extractBegLen at org/jruby/ext/strscan/RubyStringScanner.java:260
                 scan at org/jruby/ext/strscan/RubyStringScanner.java:342
                 scan at org/jruby/ext/strscan/RubyStringScanner.java:391

This is the cause of jruby/jruby#8083. FIx coming.

Activity

  1. added a commit that references this issue on Feb 3, 2024
    43cd1c7
  2. added 2 commits that reference this issue on Feb 3, 2024
    c17b015
    f86ea7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions