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

Fix bug in array pack with shared strings #6704

Merged
merged 1 commit into from Nov 10, 2022

Conversation

jemmaissroff
Copy link
Contributor

If string literals are long and they become shared, we need to make them independent before we can write to them. [Bug #19116]

Confirmed that the test added was previously failing, and is now passing.

def test_pack_with_buffer
# Fixes [Bug #19116]
n = [ 65, 66, 67 ]
super_long_string = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key thing here is that this string is shared isn't it? Can we deliberately create it as shared, and assert that it's shared, in this test, so that if sharing heuristics change the test doesn't stop testing what we think it does.

pack.c Outdated Show resolved Hide resolved
@jemmaissroff jemmaissroff force-pushed the pack-pack-fix branch 2 times, most recently from dd05562 to 56b5af2 Compare November 9, 2022 23:43
test/ruby/test_array.rb Outdated Show resolved Hide resolved
Comment on lines 1298 to 1301
# Fixes [Bug #19116]
n = [ 65, 66, 67 ]
str = "a" * 100
assert_equal("aaaABC", n.pack("@3ccc", buffer: str.dup))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper message would be better than a comment.

Suggested change
# Fixes [Bug #19116]
n = [ 65, 66, 67 ]
str = "a" * 100
assert_equal("aaaABC", n.pack("@3ccc", buffer: str.dup))
n = [ 65, 66, 67 ]
str = "a" * 100
assert_equal("aaaABC", n.pack("@3ccc", buffer: str.dup), "[Bug #19116]")

pack.c Outdated Show resolved Hide resolved
If string literals are long and they become shared, we need to make them
independent before we can write to them. [Bug #19116]
@peterzhu2118 peterzhu2118 merged commit 199b59f into ruby:master Nov 10, 2022
@jemmaissroff jemmaissroff deleted the pack-pack-fix branch November 10, 2022 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants