[#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:105336] [Ruby master Bug#18141] Marshal load with proc yield strings before they are fully initialized
From:
"nagachika (Tomoyuki Chikanaga)" <noreply@...>
Date:
2021-09-18 07:34:58 UTC
List:
ruby-core #105336
Issue #18141 has been updated by nagachika (Tomoyuki Chikanaga).
Hello byroot,
Thank you for the investigation about the issue. Yes, the patch with only the bug fix is very helpful to maintain stable branches.
----------------------------------------
Bug #18141: Marshal load with proc yield strings before they are fully initialized
https://bugs.ruby-lang.org/issues/18141#change-93750
* Author: byroot (Jean Boussier)
* Status: Closed
* Priority: Normal
* Backport: 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED
----------------------------------------
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:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>