Skip to content

Commit

Permalink
Make String#undump compaction safe
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Dec 1, 2023
1 parent 80ea7fb commit ee0eca1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions string.c
Expand Up @@ -7231,6 +7231,8 @@ str_undump(VALUE str)
}
}

RB_GC_GUARD(str);

return undumped;
invalid_format:
rb_raise(rb_eRuntimeError, "invalid dumped string; not wrapped with '\"' nor '\"...\".force_encoding(\"...\")' form");
Expand Down
11 changes: 11 additions & 0 deletions test/ruby/test_string.rb
Expand Up @@ -896,6 +896,17 @@ def test_undump
}
end

def test_undump_gc_compact_stress
a = S("Test") << 1 << 2 << 3 << 9 << 13 << 10
EnvUtil.under_gc_compact_stress do
assert_equal(a, S('"Test\\x01\\x02\\x03\\t\\r\\n"').undump)
end

EnvUtil.under_gc_compact_stress do
assert_equal(S("\u{ABCDE 10ABCD}"), S('"\\u{ABCDE 10ABCD}"').undump)
end
end

def test_dup
for frozen in [ false, true ]
a = S("hello")
Expand Down

0 comments on commit ee0eca1

Please sign in to comment.