File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -13139,6 +13139,7 @@ copy_stream_fallback_body(VALUE arg)
13139
13139
while (1 ) {
13140
13140
long numwrote ;
13141
13141
long l ;
13142
+ rb_str_make_independent (buf );
13142
13143
if (stp -> copy_length < (rb_off_t )0 ) {
13143
13144
l = buflen ;
13144
13145
}
Original file line number Diff line number Diff line change @@ -1141,6 +1141,34 @@ def test_copy_stream_pathname_to_pathname
1141
1141
}
1142
1142
end
1143
1143
1144
+ def test_copy_stream_dup_buffer
1145
+ bug21131 = '[ruby-core:120961] [Bug #21131]'
1146
+ mkcdtmpdir do
1147
+ dst_class = Class . new do
1148
+ def initialize ( &block )
1149
+ @block = block
1150
+ end
1151
+
1152
+ def write ( data )
1153
+ @block . call ( data . dup )
1154
+ data . bytesize
1155
+ end
1156
+ end
1157
+
1158
+ rng = Random . new ( 42 )
1159
+ body = Tempfile . new ( "ruby-bug" , binmode : true )
1160
+ body . write ( rng . bytes ( 16_385 ) )
1161
+ body . rewind
1162
+
1163
+ payload = [ ]
1164
+ IO . copy_stream ( body , dst_class . new { payload << it } )
1165
+ body . rewind
1166
+ assert_equal ( body . read , payload . join , bug21131 )
1167
+ ensure
1168
+ body &.close
1169
+ end
1170
+ end
1171
+
1144
1172
def test_copy_stream_write_in_binmode
1145
1173
bug8767 = '[ruby-core:56518] [Bug #8767]'
1146
1174
mkcdtmpdir {
You can’t perform that action at this time.
0 commit comments