ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership
@ 2024-09-18 13:29 hanazuki (Kasumi Hanazuki) via ruby-core
  2024-09-30  5:20 ` [ruby-core:119348] " mame (Yusuke Endoh) via ruby-core
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hanazuki (Kasumi Hanazuki) via ruby-core @ 2024-09-18 13:29 UTC (permalink / raw)
  To: ruby-core; +Cc: hanazuki (Kasumi Hanazuki)

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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119348] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership
  2024-09-18 13:29 [ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership hanazuki (Kasumi Hanazuki) via ruby-core
@ 2024-09-30  5:20 ` mame (Yusuke Endoh) via ruby-core
  2024-09-30 13:54 ` [ruby-core:119361] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-09-30  5:20 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119361] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership
  2024-09-18 13:29 [ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership hanazuki (Kasumi Hanazuki) via ruby-core
  2024-09-30  5:20 ` [ruby-core:119348] " mame (Yusuke Endoh) via ruby-core
@ 2024-09-30 13:54 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-10-21  8:50 ` [ruby-core:119547] " nagachika (Tomoyuki Chikanaga) via ruby-core
  2024-11-04 22:39 ` [ruby-core:119711] " k0kubun (Takashi Kokubun) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-09-30 13:54 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119547] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership
  2024-09-18 13:29 [ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership hanazuki (Kasumi Hanazuki) via ruby-core
  2024-09-30  5:20 ` [ruby-core:119348] " mame (Yusuke Endoh) via ruby-core
  2024-09-30 13:54 ` [ruby-core:119361] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-10-21  8:50 ` nagachika (Tomoyuki Chikanaga) via ruby-core
  2024-11-04 22:39 ` [ruby-core:119711] " k0kubun (Takashi Kokubun) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: nagachika (Tomoyuki Chikanaga) via ruby-core @ 2024-10-21  8:50 UTC (permalink / raw)
  To: ruby-core; +Cc: nagachika (Tomoyuki Chikanaga)

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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:119711] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership
  2024-09-18 13:29 [ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership hanazuki (Kasumi Hanazuki) via ruby-core
                   ` (2 preceding siblings ...)
  2024-10-21  8:50 ` [ruby-core:119547] " nagachika (Tomoyuki Chikanaga) via ruby-core
@ 2024-11-04 22:39 ` k0kubun (Takashi Kokubun) via ruby-core
  3 siblings, 0 replies; 5+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2024-11-04 22:39 UTC (permalink / raw)
  To: ruby-core; +Cc: k0kubun (Takashi Kokubun)

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/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-11-04 22:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 13:29 [ruby-core:119257] [Ruby master Bug#20755] IO::Buffer#transfer transfers mutable reference to String's memory but not lock ownership hanazuki (Kasumi Hanazuki) via ruby-core
2024-09-30  5:20 ` [ruby-core:119348] " mame (Yusuke Endoh) via ruby-core
2024-09-30 13:54 ` [ruby-core:119361] " nobu (Nobuyoshi Nakada) via ruby-core
2024-10-21  8:50 ` [ruby-core:119547] " nagachika (Tomoyuki Chikanaga) via ruby-core
2024-11-04 22:39 ` [ruby-core:119711] " k0kubun (Takashi Kokubun) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).