8000 merge revision(s) f423f6e10c0c226dfed98e7cb7a5d489191dfa35: [Backport… · github/ruby@f85e5e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f85e5e0

Browse files
committed
merge revision(s) f423f6e: [Backport #21131]
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]
1 parent 2b2ab1a commit f85e5e0

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13098,6 +13098,7 @@ copy_stream_fallback_body(VALUE arg)
1309813098
while (1) {
1309913099
long numwrote;
1310013100
long l;
13101+
rb_str_make_independent(buf);
1310113102
if (stp->copy_length < (rb_off_t)0) {
1310213103
l = buflen;
1310313104
}

test/ruby/test_io.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,34 @@ def test_copy_stream_pathname_to_pathname
11161116
}
11171117
end
11181118

1119+
def test_copy_stream_dup_buffer
1120+
bug21131 = '[ruby-core:120961] [Bug #21131]'
1121+
mkcdtmpdir do
1122+
dst_class = Class.new do
1123+
def initialize(&block)
1124+
@block = block
1125+
end
1126+
1127+
def write(data)
1128+
@block.call(data.dup)
1129+
data.bytesize
1130+
end
1131+
end
1132+
1133+
rng = Random.new(42)
1134+
body = Tempfile.new("ruby-bug", binmode: true)
1135+
body.write(rng.bytes(16_385))
1136+
body.rewind
1137+
1138+
payload = []
1139+
IO.copy_stream(body, dst_class.new{|cls| payload << cls})
1140+
body.rewind
1141+
assert_equal(body.read, payload.join, bug21131)
1142+
ensure
1143+
body&.close
1144+
end
1145+
end
1146+
11191147
def test_copy_stream_write_in_binmode
11201148
bug8767 = '[ruby-core:56518] [Bug #8767]'
11211149
mkcdtmpdir {

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 7
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 134
14+
#define RUBY_PATCHLEVEL 135
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)
0