Skip to content

Conversation

tompng
Copy link
Member

@tompng tompng commented Oct 4, 2025

Fixes #870

bb = ByteBuffer.wrap(array, offset, length);
bb.getLong(); // Reads from offset and increment offset. ByteBuffer's offset is mutable.
bb.getLong(idx); // Reads from idx, not from offset+idx
bb.getLong(offset + idx); // What we need

ByteBuffer.wrap(array, 0, ptr + len) vs ByteBuffer.wrap(array)

array.length does not match ptr+len for a sliced string. Specifying ptr+len seems more safe.

Test string

'01234567890123456789"a"b"c"d"e"f"g"h'[20, 15]
First 15 bytes don't need escape.
15 = 8 + 4 + 3, which can test getLong, getInt and remaining bytes escaping

@byroot byroot merged commit eec466d into ruby:master Oct 5, 2025
37 checks passed
@byroot
Copy link
Member

byroot commented Oct 5, 2025

Thank you!

@tompng tompng deleted the fix_sliced_string_escape branch October 5, 2025 08:10
@headius
Copy link
Contributor

headius commented Oct 6, 2025

Aha, another buffer-wrapping issue. Thanks for jumping on this!

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.

JRuby isn't escaping strings correctly

3 participants