[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
SXNzdWUgIzE4MjI4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku
11 messages
2021/09/27
[ruby-core:105107] [Ruby master Bug#18141] Marshal load with proc yield strings before they are fully initialized
From:
"byroot (Jean Boussier)" <noreply@...>
Date:
2021-09-01 17:57:21 UTC
List:
ruby-core #105107
Issue #18141 has been updated by byroot (Jean Boussier).
I potentially have a fix: https://github.com/ruby/ruby/pull/4797
----------------------------------------
Bug #18141: Marshal load with proc yield strings before they are fully initialized
https://bugs.ruby-lang.org/issues/18141#change-93518
* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
I assume this is a bug because I can't find any spec or test for this behaviour:
Consider the following script:
```ruby
payload = Marshal.dump("foo")
Marshal.load(payload, -> (obj) {
if obj.is_a?(String)
p [obj, obj.encoding]
end
obj
})
p [:final, string, string.encoding]
```
outputs:
```ruby
["foo", #<Encoding:ASCII-8BIT>]
[:final, "foo", #<Encoding:UTF-8>]
```
So `Marshal` call the proc before the string get its encoding assigned, this is because the encoding is stored alongside as a `TYPE_IVAR`. I think in such cases `Marshal` should delay calling the proc until the object is fully restored.
A corollary to this behaviour is that the following code:
```ruby
Marshal.load(payload, :freeze.to_proc)
```
raises with `can't modify frozen String: "foo" (FrozenError)`.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>