Actions
Bug #20755
closedIO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership
ruby -v:
ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux]
Description
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(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"
Updated by nobu (Nobuyoshi Nakada) about 1 month ago
- Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
Updated by mame (Yusuke Endoh) 20 days ago
- Assignee set to ioquatix (Samuel Williams)
Updated by nobu (Nobuyoshi Nakada) 19 days ago
Updated by nobu (Nobuyoshi Nakada) 18 days ago
- Status changed from Open to Closed
Applied in changeset git|35e124832e29b65c84d4e0e4e434616859f9bdf5.
[Bug #20755] Frozen string should not be writable via IO::Buffer
Updated by nagachika (Tomoyuki Chikanaga) 1 day ago
- 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) 35e124832e29b65c84d4e0e4e434616859f9bdf5.
Actions
Like0
Like0Like0Like0Like0Like0