From: "byroot (Jean Boussier)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105107] [Ruby master Bug#18141] Marshal load with proc yield strings before they are fully initialized
Date: Wed, 01 Sep 2021 17:57:21 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-93518.20210901175721.7941@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18141.20210901081741.7941@ruby-lang.org
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/
next prev parent reply other threads:[~2021-09-01 17:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-01 8:17 [ruby-core:105104] [Ruby master Bug#18141] Marshal load with proc yield strings before they are fully initialized byroot (Jean Boussier)
2021-09-01 17:57 ` byroot (Jean Boussier) [this message]
2021-09-02 0:40 ` [ruby-core:105113] " nobu (Nobuyoshi Nakada)
2021-09-17 14:19 ` [ruby-core:105327] " byroot (Jean Boussier)
2021-09-18 7:34 ` [ruby-core:105336] " nagachika (Tomoyuki Chikanaga)
2021-09-18 13:45 ` [ruby-core:105342] " byroot (Jean Boussier)
2021-09-28 8:42 ` [ruby-core:105462] [Ruby master Bug#18141] Marshal load with proc yield objects " byroot (Jean Boussier)
2021-09-30 15:33 ` [ruby-core:105509] " byroot (Jean Boussier)
2021-10-09 6:37 ` [ruby-core:105611] " nagachika (Tomoyuki Chikanaga)
2021-11-24 10:36 ` [ruby-core:106261] " usa (Usaku NAKAMURA)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-93518.20210901175721.7941@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).