truffleruby icon indicating copy to clipboard operation
truffleruby copied to clipboard

Java exception escaping in `Array#[]=` with overflowed index

Open nirvdrum opened this issue 2 years ago • 0 comments

I'm working on refreshing our tags for the MRI tests. While doing so, I ran into a situation where a Java exception is escaping into Ruby. I don't think this particular example is really something that's problematic, only that it suggests we're missing some exception handling somewhere.

LONGP = [127, 63, 31, 15, 7].map {|x| 2**x-1 }.find do |x|
  begin
    [].first(x)
  rescue ArgumentError
    true
  rescue RangeError
    false
  end
end

puts "Bad index: #{LONGP}"
Puts [0][LONGP] = [2]
> jt ruby bad-array.rb
truffleruby 23.0.0-dev-671182fb*, like ruby 3.1.3, GraalVM CE JVM [aarch64-darwin]
Bad index: 2147483647

truffleruby: an internal exception escaped out of the interpreter,
please report it to https://github.com/oracle/truffleruby/issues.

-2147483648 (java.lang.NegativeArraySizeException)
        from org.truffleruby.core.array.library.ObjectArrayStore$ObjectArrayAllocator.allocate(ObjectArrayStore.java:230)
        from org.truffleruby.core.array.library.ObjectArrayStore$ObjectArrayAllocator.allocate(ObjectArrayStore.java:226)
        from org.truffleruby.core.array.library.IntegerArrayStore$AllocateForNewValue.allocateForNewValue(IntegerArrayStore.java:276)
        from org.truffleruby.core.array.library.IntegerArrayStoreGen$ArrayStoreLibraryExports$Cached.allocateForNewValueAndSpecialize(IntegerArrayStoreGen.java:721)
        from org.truffleruby.core.array.library.IntegerArrayStoreGen$ArrayStoreLibraryExports$Cached.allocateForNewValue(IntegerArrayStoreGen.java:696)
        from org.truffleruby.core.array.ArrayWriteNormalizedNode.writeBeyondPrimitive(ArrayWriteNormalizedNode.java:87)
        from org.truffleruby.core.array.ArrayWriteNormalizedNodeGen.executeAndSpecialize(ArrayWriteNormalizedNodeGen.java:471)
        from org.truffleruby.core.array.ArrayWriteNormalizedNodeGen.executeWrite(ArrayWriteNormalizedNodeGen.java:237)
        from org.truffleruby.core.array.ArrayNodes$SetIndexNode.set(ArrayNodes.java:358)
        from org.truffleruby.core.array.ArrayNodesFactory$SetIndexNodeFactory$SetIndexNodeGen.executeAndSpecialize(ArrayNodesFactory.java:2039)
        from org.truffleruby.core.array.ArrayNodesFactory$SetIndexNodeFactory$SetIndexNodeGen.execute(ArrayNodesFactory.java:2014)
        from org.truffleruby.language.RubyCoreMethodRootNode.execute(RubyCoreMethodRootNode.java:58)
bad-array.rb:12:in `[]='
        from bad-array.rb:12:in `<main>'

nirvdrum avatar Mar 10 '23 04:03 nirvdrum