From 722c45f64110be876d83e7f9a22592aa954886c1 Mon Sep 17 00:00:00 2001 From: Aaron Lipman Date: Mon, 8 Jul 2019 13:55:28 -0400 Subject: Omit marshal_dump & _dump from delegate_missing_to Exclude missing marshal_dump and _dump methods from being delegated to an object's delegation target via the delegate_missing_to extension. This avoids unintentionally adding instance variables to an object during marshallization, should the delegation target be a method which would otherwise add them. In current versions of Ruby, a bug exists in the way objects are marshalled, allowing for instance variables to be added or removed during marshallization (see https://bugs.ruby-lang.org/issues/15968). This results in a corrupted serialized byte stream, causing an object's instance variables to "leak" into subsequent serialized objects during demarshallization. In Rails, this behavior may be triggered when marshalling an object that uses the delegate_missing_to extension, if the delegation target is a method which adds or removes instance variables to an object being marshalled - when calling Marshal.dump(object), Ruby's built in behavior will check whether the object responds to :marshal_dump or :_dump, which in turn triggers the delegation target method in the responds_to_missing? function defined in activesupport/lib/active_support/core_ext/module/delegation.rb While future versions of Ruby will resolve this bug by raising a RuntimeError, the underlying cause of this error may not be readily apparent when encountered by Rails developers. By excluding marshal_dump and _dump from being delegated to an object's target, this commit eliminates a potential cause of unexpected behavior and/or RuntimeErrors. Fixes #36522 --- activesupport/CHANGELOG.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activesupport/CHANGELOG.md') diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index d56d4c22de..1776972dd7 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,12 @@ -* Allow the `on_rotation` proc used when decrypting/verifying a message to be - passed at the constructor level. +* Do not delegate missing `marshal_dump` and `_dump` methods via the + `delegate_missing_to` extension. This avoids unintentionally adding instance + variables when calling `Marshal.dump(object)`, should the delegation target of + `object` be a method which would otherwise add them. Fixes #36522. + + *Aaron Lipman* + +* Allow the on_rotation proc used when decrypting/verifying a message to be + be passed at the constructor level. Before: -- cgit v1.2.3