From a86f798fc2e979ea83ec55744f906b2a816c8681 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 23 May 2023 13:45:44 -0400 Subject: Fix crash when replacing ST hash with AR hash With VWA, AR hashes are much larger than ST hashes. Hash#replace attempts to directly copy the contents of AR hashes into ST hashes so there will be memory corruption caused by writing past the end of memory. This commit changes it so that if a ST hash is being replaced with an AR hash it will insert each element into the ST hash. --- test/ruby/test_hash.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 8b6065146c..d9d1ca7dde 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -850,6 +850,16 @@ class TestHash < Test::Unit::TestCase assert(true) end + def test_replace_st_with_ar + # ST hash + h1 = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9 } + # AR hash + h2 = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7 } + # Replace ST hash with AR hash + h1.replace(h2) + assert_equal(h2, h1) + end + def test_shift h = @h.dup -- cgit v1.2.3