[ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership

Issue #20755 has been reported by hanazuki (Kasumi Hanazuki). ---------------------------------------- Bug #20755: IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership https://bugs.ruby-lang.org/issues/20755 * Author: hanazuki (Kasumi Hanazuki) * Status: Open * ruby -v: ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- `IO::Buffer.for` with a block yields a mutable IO::Buffer that shares underlying memory with a mutable String. While the block is executed, the String instance is temporarily locked and cannot be modified or frozen. If you call `#transfer` on the yielded IO::Buffer in the block, however, a mutable IO::Buffer can be escaped from the `.for` method. Through this IO::Buffer instance, you can modify the underlying String memory even after the String instance is frozen. ```irb irb(main):001> str = +'a' => "a" irb(main):002> buf = IO::Buffer.for(str) {|b| b.transfer } => #<IO::Buffer 0x00007f244d1ede98+1 EXTERNAL SLICE> ... irb(main):003> str.freeze => "a" irb(main):004> buf.set_string('b') => 1 irb(main):005> str => "b" ``` -- https://bugs.ruby-lang.org/

Issue #20755 has been updated by mame (Yusuke Endoh). Assignee set to ioquatix (Samuel Williams) ---------------------------------------- Bug #20755: IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership https://bugs.ruby-lang.org/issues/20755#change-109960 * Author: hanazuki (Kasumi Hanazuki) * Status: Open * Assignee: ioquatix (Samuel Williams) * ruby -v: ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux] * Backport: 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED ---------------------------------------- `IO::Buffer.for` with a block yields a mutable IO::Buffer that shares underlying memory with a mutable String. While the block is executed, the String instance is temporarily locked and cannot be modified or frozen. If you call `#transfer` on the yielded IO::Buffer in the block, however, a mutable IO::Buffer can be escaped from the `.for` method. Through this IO::Buffer instance, you can modify the underlying String memory even after the String instance is frozen. ```irb irb(main):001> str = +'a' => "a" irb(main):002> buf = IO::Buffer.for(str) {|b| b.transfer } => #<IO::Buffer 0x00007f244d1ede98+1 EXTERNAL SLICE> ... irb(main):003> str.freeze => "a" irb(main):004> buf.set_string('b') => 1 irb(main):005> str => "b" ``` -- https://bugs.ruby-lang.org/

Issue #20755 has been updated by nobu (Nobuyoshi Nakada). https://github.com/ruby/ruby/pull/11738 ---------------------------------------- Bug #20755: IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership https://bugs.ruby-lang.org/issues/20755#change-109973 * Author: hanazuki (Kasumi Hanazuki) * Status: Open * Assignee: ioquatix (Samuel Williams) * ruby -v: ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux] * Backport: 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED ---------------------------------------- `IO::Buffer.for` with a block yields a mutable IO::Buffer that shares underlying memory with a mutable String. While the block is executed, the String instance is temporarily locked and cannot be modified or frozen. If you call `#transfer` on the yielded IO::Buffer in the block, however, a mutable IO::Buffer can be escaped from the `.for` method. Through this IO::Buffer instance, you can modify the underlying String memory even after the String instance is frozen. ```irb irb(main):001> str = +'a' => "a" irb(main):002> buf = IO::Buffer.for(str) {|b| b.transfer } => #<IO::Buffer 0x00007f244d1ede98+1 EXTERNAL SLICE> ... irb(main):003> str.freeze => "a" irb(main):004> buf.set_string('b') => 1 irb(main):005> str => "b" ``` -- https://bugs.ruby-lang.org/

Issue #20755 has been updated by nagachika (Tomoyuki Chikanaga). Backport changed from 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED ruby_3_2 commit:087e4ed6cc9da9cfca1a107058905446ff474bd1 merged revision(s) commit:35e124832e29b65c84d4e0e4e434616859f9bdf5. ---------------------------------------- Bug #20755: IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership https://bugs.ruby-lang.org/issues/20755#change-110161 * Author: hanazuki (Kasumi Hanazuki) * Status: Closed * Assignee: ioquatix (Samuel Williams) * ruby -v: ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux] * Backport: 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED ---------------------------------------- `IO::Buffer.for` with a block yields a mutable IO::Buffer that shares underlying memory with a mutable String. While the block is executed, the String instance is temporarily locked and cannot be modified or frozen. If you call `#transfer` on the yielded IO::Buffer in the block, however, a mutable IO::Buffer can be escaped from the `.for` method. Through this IO::Buffer instance, you can modify the underlying String memory even after the String instance is frozen. ```irb irb(main):001> str = +'a' => "a" irb(main):002> buf = IO::Buffer.for(str) {|b| b.transfer } => #<IO::Buffer 0x00007f244d1ede98+1 EXTERNAL SLICE> ... irb(main):003> str.freeze => "a" irb(main):004> buf.set_string('b') => 1 irb(main):005> str => "b" ``` -- https://bugs.ruby-lang.org/

Issue #20755 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: DONE ruby_3_3 commit:5ce0ba0d415deb99527c409cc5f1df16ce02ef3e merged revision(s) commit:35e124832e29b65c84d4e0e4e434616859f9bdf5. ---------------------------------------- Bug #20755: IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership https://bugs.ruby-lang.org/issues/20755#change-110375 * Author: hanazuki (Kasumi Hanazuki) * Status: Closed * Assignee: ioquatix (Samuel Williams) * ruby -v: ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux] * Backport: 3.1: REQUIRED, 3.2: DONE, 3.3: DONE ---------------------------------------- `IO::Buffer.for` with a block yields a mutable IO::Buffer that shares underlying memory with a mutable String. While the block is executed, the String instance is temporarily locked and cannot be modified or frozen. If you call `#transfer` on the yielded IO::Buffer in the block, however, a mutable IO::Buffer can be escaped from the `.for` method. Through this IO::Buffer instance, you can modify the underlying String memory even after the String instance is frozen. ```irb irb(main):001> str = +'a' => "a" irb(main):002> buf = IO::Buffer.for(str) {|b| b.transfer } => #<IO::Buffer 0x00007f244d1ede98+1 EXTERNAL SLICE> ... irb(main):003> str.freeze => "a" irb(main):004> buf.set_string('b') => 1 irb(main):005> str => "b" ``` -- https://bugs.ruby-lang.org/
participants (5)
-
hanazuki (Kasumi Hanazuki)
-
k0kubun (Takashi Kokubun)
-
mame (Yusuke Endoh)
-
nagachika (Tomoyuki Chikanaga)
-
nobu (Nobuyoshi Nakada)