diff options
author | Jeremy Evans <[email protected]> | 2025-02-17 17:23:14 -0800 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2025-02-18 17:18:16 -0800 |
commit | f423f6e10c0c226dfed98e7cb7a5d489191dfa35 (patch) | |
tree | 0555c3ee3f374d762cbf355ae23c85f91bdb00a2 /test/ruby/test_io.rb | |
parent | 6e510d78c02d78d335f09f5175c73c4794fe0378 (diff) |
Ensure IO.copy_stream buffer is an independent string
Otherwise, changes to the buffer by the destination write method
could result in data changing for supposedly independent strings.
Fixes [Bug #21131]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12771
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r-- | test/ruby/test_io.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 999bbd9d2a..3668085d83 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1141,6 +1141,34 @@ class TestIO < Test::Unit::TestCase } end + def test_copy_stream_dup_buffer + bug21131 = '[ruby-core:120961] [Bug #21131]' + mkcdtmpdir do + dst_class = Class.new do + def initialize(&block) + @block = block + end + + def write(data) + @block.call(data.dup) + data.bytesize + end + end + + rng = Random.new(42) + body = Tempfile.new("ruby-bug", binmode: true) + body.write(rng.bytes(16_385)) + body.rewind + + payload = [] + IO.copy_stream(body, dst_class.new{payload << it}) + body.rewind + assert_equal(body.read, payload.join, bug21131) + ensure + body&.close + end + end + def test_copy_stream_write_in_binmode bug8767 = '[ruby-core:56518] [Bug #8767]' mkcdtmpdir { |