Actions
Bug #20752
closedIO::Buffer#slice creates mutable IO::Buffer instance that points to readonly memory (e.g. fronzen String)
ruby -v:
ruby 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux]
Backport:
Description
irb(main):001> RUBY_DESCRIPTION.frozen?
=> true
irb(main):002> IO::Buffer.for(RUBY_DESCRIPTION).set_string('perl', 0, 4)
(irb):2:in 'IO::Buffer#set_string': Buffer is not writable! (IO::Buffer::AccessError)
from (irb):2:in '<main>'
from <internal:kernel>:191:in 'Kernel#loop'
from -e:1:in '<main>'
irb(main):003> IO::Buffer.for(RUBY_DESCRIPTION).slice.set_string('perl', 0, 4)
=> 4
irb(main):004> RUBY_DESCRIPTION
=> "perl 3.4.0dev (2024-09-18T02:16:22Z master 4797b0704a) +PRISM [x86_64-linux]"
irb(main):001> IO::Buffer.for(NameError.name).slice.set_string('X', 0, 1)
=> 1
irb(main):002> NameError
(irb):2:in '<main>': uninitialized constant NameError (XameError)
from <internal:kernel>:191:in 'Kernel#loop'
from -e:1:in '<main>'
Updated by nobu (Nobuyoshi Nakada) 3 months ago
- Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
It results in bus errors with 3.1 and 3.2.
$ ruby3.2 -e 'IO::Buffer.for(RUBY_DESCRIPTION).slice.set_string("perl", 0, 4)'
-e:1: [BUG] Bus Error at 0x0000000100f08b18
ruby 3.2.5 (2024-07-26 revision 31d0f1a2e7) [arm64-darwin23]
$ ruby3.1 -e 'IO::Buffer.for(RUBY_DESCRIPTION).slice(0, 8).set_string("perl", 0, 4)'
-e:1: [BUG] Bus Error at 0x00000001039c7e38
ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [arm64-darwin23]
Updated by hanazuki (Kasumi Hanazuki) 3 months ago
- Subject changed from IO::Buffer#slice fails to copy readonly flag, allowing writes into frozen String to IO::Buffer#slice creates mutable IO::Buffer instance that points to readonly memory (e.g. fronzen String)
Updated by mame (Yusuke Endoh) 3 months ago
- Assignee set to ioquatix (Samuel Williams)
Updated by ioquatix (Samuel Williams) 3 months ago
The second example XameError
is hilarious, what a great bug. Yes, this should be fixed.
Updated by ioquatix (Samuel Williams) 3 months ago
Looks like @nobu (Nobuyoshi Nakada) already made a PR here: https://github.com/ruby/ruby/pull/11735
Updated by nobu (Nobuyoshi Nakada) 3 months ago
- Status changed from Open to Closed
Updated by nagachika (Tomoyuki Chikanaga) 2 months 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 5777fe5ab57d6479326bdb21ef9a6b88ea1516dc merged revision(s) 637067440f74043c6d79fc649ab8acf1afea25a5.
Updated by k0kubun (Takashi Kokubun) about 2 months ago
- 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 12ea98e8c8af0ed6778aad26e7ec5f95e2c239e5 merged revision(s) 637067440f74043c6d79fc649ab8acf1afea25a5.
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0