aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_argf.rb
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2020-08-12 04:54:09 -0400
committerGitHub <noreply@github.com>2020-08-12 17:54:09 +0900
commit166cacc505e5a0d807712e9cb5b6919a7d190a6e (patch)
treebfecacac9a13ab87d5afe1b0fdc22ca79931706f /test/ruby/test_argf.rb
parente79cdcf61b0665d8a9bb309a607227de43e95673 (diff)
downloadruby-166cacc505e5a0d807712e9cb5b6919a7d190a6e.tar.gz
Fix corruption in ARGF.inplace
Extension string stored in `ARGF.inplace` is created using an api designed for C string constants to create a Ruby string that points at another Ruby string. When the original string is swept, the extension string gets corrupted. Reproduction script (on MacOS): ```ruby #!/usr/bin/ruby -pi.bak BEGIN { GC.start(full_mark: true) arr = [] 1000000.times do |x| arr << "fooo#{x}" end } puts "hello" ``` Co-Authored-By: Matt Valentine-House <31869+eightbitraptor@users.noreply.github.com>
Diffstat (limited to 'test/ruby/test_argf.rb')
-rw-r--r--test/ruby/test_argf.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index 277fa368f5..4734d5b3ae 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -387,6 +387,21 @@ class TestArgf < Test::Unit::TestCase
assert_equal("foo", File.read(name+suffix))
end
+ def test_inplace_bug_17117
+ assert_in_out_err(["-", @t1.path], "#{<<~"{#"}#{<<~'};'}")
+ {#
+ #!/usr/bin/ruby -pi.bak
+ BEGIN {
+ GC.start
+ arr = []
+ 1000000.times { |x| arr << "fooo#{x}" }
+ }
+ puts "hello"
+ };
+ assert_equal("hello\n1\nhello\n2\n", File.read(@t1.path))
+ assert_equal("1\n2\n", File.read("#{@t1.path}.bak"))
+ end
+
def test_encoding
ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
{#