Skip to content

Fix sliced string escaping#871

Merged
byroot merged 1 commit into
ruby:masterfrom
tompng:fix_sliced_string_escape
Oct 5, 2025
Merged

Fix sliced string escaping#871
byroot merged 1 commit into
ruby:masterfrom
tompng:fix_sliced_string_escape

Conversation

@tompng

@tompng tompng commented Oct 4, 2025

Copy link
Copy Markdown
Member

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

byroot commented Oct 5, 2025

Copy link
Copy Markdown
Member

Thank you!

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

headius commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

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