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_HI,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 4B61E1F8C6 for ; Wed, 1 Sep 2021 17:57:28 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 14578120AE3; Thu, 2 Sep 2021 02:56:05 +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 35C57120ADC for ; Thu, 2 Sep 2021 02:56:03 +0900 (JST) Received: by filterdrecv-5d6f795d94-n6wkv with SMTP id filterdrecv-5d6f795d94-n6wkv-1-612FBF01-40 2021-09-01 17:57:21.770723245 +0000 UTC m=+1626793.422988995 Received: from herokuapp.com (unknown) by geopod-ismtpd-1-3 (SG) with ESMTP id VfRuxO9pSm-1NoWiSEiHJA for ; Wed, 01 Sep 2021 17:57:21.683 +0000 (UTC) Date: Wed, 01 Sep 2021 17:57:21 +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: 81285 X-SG-EID: =?us-ascii?Q?Dq8GNIcVqP8cs5uR+EIAabfg3LE9XdC6dZ5KYNrMpf6VzBWG6HqArcu5raQjXL?= =?us-ascii?Q?IGTFdxKHUt7++67+KD54pNYXheirMcsUIf3sdgF?= =?us-ascii?Q?Riq06jTvt=2FomHiCTPTlL27Q3B4ciuWHhhosms1+?= =?us-ascii?Q?lSuKRe5tWzBqPOtW0EXrVFlcY2eQOLIWh=2F0o2Vu?= =?us-ascii?Q?sp8kwDkRpSRxKkpxoSGCTJtEqSce7t=2FHz9A9sYO?= =?us-ascii?Q?D0DhKZIrF8clWL+klIbmZ2RDsk7HLkw=2FqCyLQT0?= =?us-ascii?Q?85RcXlizxDTaXbYJoxmWA=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 105107 Subject: [ruby-core:105107] [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 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", #] [: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/