[ruby-core:113339] [Ruby master Bug#19427] Marshal.load(source, freeze: true) doesn't freeze in some cases
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2023-04-25 14:52:00 UTC
List:
ruby-core #113339
Issue #19427 has been updated by Eregon (Benoit Daloze).
Revert https://github.com/ruby/spec/commit/036134c0c6af8e01ae150db5e2ac6c5d70364a10 once this is fixed
----------------------------------------
Bug #19427: Marshal.load(source, freeze: true) doesn't freeze in some cases
https://bugs.ruby-lang.org/issues/19427#change-102899
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* Assignee: byroot (Jean Boussier)
* ruby -v: 3.1
* Backport: 2.7: DONTNEED, 3.0: DONTNEED, 3.1: REQUIRED, 3.2: REQUIRED
----------------------------------------
I've noticed that the `freeze` option doesn't work in the following cases:
- when dumped object extends a module
- when dumped object responds to `#marshal_dump` and `#marshal_load` methods
- when dumped object responds to `#_dump` method
Is it expected behaviour or maybe a known issue?
Examples:
```ruby
module M
end
object = Object.new
object.extend(M)
object = Marshal.load(Marshal.dump(object), freeze: true)
object.frozen? # => false
```
```ruby
class UserMarshal
attr_accessor :data
def initialize
@data = 'stuff'
end
def marshal_dump() :data end
def marshal_load(data) @data = data end
end
object = Marshal.load(Marshal.dump(UserMarshal.new), freeze: true)
object.frozen? # => false
```
```ruby
class UserDefined
attr_reader :a, :b
def initialize
@a = 'stuff'
@b = @a
end
def _dump(depth)
Marshal.dump [:stuff, :stuff]
end
def self._load(data)
a, b = Marshal.load data
obj = allocate
obj.instance_variable_set :@a, a
obj.instance_variable_set :@b, b
obj
end
end
object = Marshal.load(Marshal.dump(UserDefined.new), freeze: true)
object.frozen? # => false
```
--
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/postorius/lists/ruby-core.ml.ruby-lang.org/