From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id A559E1F8C8 for ; Sat, 18 Sep 2021 13:46:06 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id DD3B6120DC0; Sat, 18 Sep 2021 22:44:37 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3A6DF120DBE for ; Sat, 18 Sep 2021 22:44:35 +0900 (JST) Received: by filterdrecv-55446c4d49-vth2g with SMTP id filterdrecv-55446c4d49-vth2g-1-6145ED91-60 2021-09-18 13:45:53.62353641 +0000 UTC m=+1437945.462860181 Received: from herokuapp.com (unknown) by ismtpd0163p1mdw1.sendgrid.net (SG) with ESMTP id --GZo3bUQ46CngRkdw2EoQ for ; Sat, 18 Sep 2021 13:45:53.532 +0000 (UTC) Date: Sat, 18 Sep 2021 13:45:53 +0000 (UTC) From: "byroot (Jean Boussier)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 18141 X-Redmine-Issue-Author: byroot X-Redmine-Sender: byroot X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 81518 X-SG-EID: =?us-ascii?Q?Dq8GNIcVqP8cs5uR+EIAabfg3LE9XdC6dZ5KYNrMpf6VzBWG6HqArcu5raQjXL?= =?us-ascii?Q?IGTFdxKHUt7++67+KD54pNYXheirMcsUIf3sdgF?= =?us-ascii?Q?Riq06hKDzbTrkvqdsIHRBiYvGeO7Y2y=2FNc=2Ffxad?= =?us-ascii?Q?KzXoNau2LJRU9PIc=2FQGFWITxY9gpmFvXaalspAi?= =?us-ascii?Q?CgnUPqYuhjaQRFiIqIf+yfHVoqzuR5P1ZQ7zpHT?= =?us-ascii?Q?vGLQFc8twpWLLsjd24WmwjnWhrSH7CdSPlIZjZL?= =?us-ascii?Q?McwCn4DMe5rzmQLj4fS5w=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105342 Subject: [ruby-core:105342] [Ruby master Bug#18141] Marshal load with proc yield strings before they are fully initialized X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #18141 has been updated by byroot (Jean Boussier). I made a followup patch: https://github.com/ruby/ruby/pull/4866 It now handle similar bugs with `Array`, `Hash` and other mutable objects. It also handle circular objects. ---------------------------------------- Bug #18141: Marshal load with proc yield strings before they are fully initialized https://bugs.ruby-lang.org/issues/18141#change-93756 * 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", #] [:final, "foo", #] ``` 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/