Make String#undump compaction safe

This commit is contained in:
Peter Zhu 2023-11-30 14:48:26 -05:00
parent 80ea7fbad8
commit ee0eca191f
2 changed files with 13 additions and 0 deletions

View File

@ -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");

View File

@ -896,6 +896,17 @@ CODE
}
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")