Skip to content

Conversation

samyron
Copy link
Contributor

@samyron samyron commented Sep 18, 2025

Hopefully resolves #859

@byroot
Copy link
Member

byroot commented Sep 18, 2025

Do you think you could craft a regression test?

@byroot
Copy link
Member

byroot commented Sep 18, 2025

Do you think you could craft a regression test?

Ok, I figured how to repro:

require "json"
s = "01234567890"
JSON.dump(s[2..-1])

@byroot byroot force-pushed the sm/fix-swar-index-out-of-bounds-exception branch from f24db70 to 9a2dd17 Compare September 18, 2025 14:11
@byroot
Copy link
Member

byroot commented Sep 18, 2025

I pushed a regression test.

@samyron
Copy link
Contributor Author

samyron commented Sep 18, 2025

I added a print statement to see what ptr is in that example:

irb(main):001> require "json"
irb(main):002> s = "01234567890"
irb(main):003> JSON.dump(s[2..-1])
ptr: 2

@samyron
Copy link
Contributor Author

samyron commented Sep 18, 2025

Without looking at the JRuby implementation of String I'm going to guess that s[2..-1] is optimized to change pointers (err, indexes) and not actually rotate the backing array...

@byroot
Copy link
Member

byroot commented Sep 18, 2025

Yes, based on https://javadoc.io/doc/org.jruby/jruby-core/9.2.9.0/org/jruby/util/ByteList.html, I assumed JRuby has a bunch of optimization to share the backing byte array between strings. That's how I figured a repro.

Fix: ruby#859

Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
@byroot byroot force-pushed the sm/fix-swar-index-out-of-bounds-exception branch from 9a2dd17 to 67ebabe Compare September 18, 2025 14:21
@byroot byroot merged commit a8ff0c8 into ruby:master Sep 18, 2025
35 checks passed
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

Successfully merging this pull request may close these issues.

IndexOutOfBoundsException during SWAR string encoding

2 participants