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

Missing String bounds checks #3792

Closed
nirvdrum opened this issue Apr 11, 2016 · 0 comments
Closed

Missing String bounds checks #3792

nirvdrum opened this issue Apr 11, 2016 · 0 comments
Milestone

Comments

@nirvdrum
Copy link
Contributor

Strings in JRuby are currently limited to signed int length. String#* expressly checks for this:

> ./bin/jruby -v -e 'p "blah" * 1_000_000_000'
jruby 9.1.0.0-SNAPSHOT (2.3.0) 2016-04-11 f79afda Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [linux-x86_64]
ArgumentError: argument too big
      * at org/jruby/RubyString.java:1161
  <top> at -e:1

However, this bound check isn't carried through to other construction operations. E.g., String#+ ends up wrapping around and a negative length array is created:

> bin/jruby -J-Xmx8g -v -e 'x = "f" * (2**31 - 3); p (x + x).size'
jruby 9.1.0.0-SNAPSHOT (2.3.0) 2016-04-11 f79afda Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [linux-x86_64]
Unhandled Java exception: java.lang.NegativeArraySizeException
java.lang.NegativeArraySizeException: null
               <init> at org/jruby/util/ByteList.java:91
         addByteLists at org/jruby/util/StringSupport.java:1630
            op_plus19 at org/jruby/RubyString.java:1149
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:313
                 call at org/jruby/runtime/callsite/CachingCallSite.java:163
                <top> at -e:1
  invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                 load at org/jruby/ir/Compiler.java:111
            runScript at org/jruby/Ruby.java:825
            runScript at org/jruby/Ruby.java:817
          runNormally at org/jruby/Ruby.java:755
          runFromMain at org/jruby/Ruby.java:576
        doRunFromMain at org/jruby/Main.java:425
          internalRun at org/jruby/Main.java:310
                  run at org/jruby/Main.java:239
                 main at org/jruby/Main.java:201
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

2 participants