mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #24150 from exviva/unmarshal-infinite-retry
Prevent `Marshal.load` from looping infinitely
This commit is contained in:
commit
e56b594d32
3 changed files with 20 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
* Prevent `Marshal.load` from looping infinitely when trying to autoload a constant
|
||||
which resolves to a different name.
|
||||
|
||||
*Olek Janiszewski*
|
||||
|
||||
* Deprecate `Module.local_constants`. Please use `Module.constants(false)` instead.
|
||||
|
||||
*Yuichiro Kaneko*
|
||||
|
|
|
@ -5,7 +5,10 @@ module ActiveSupport
|
|||
rescue ArgumentError, NameError => exc
|
||||
if exc.message.match(%r|undefined class/module (.+)|)
|
||||
# try loading the class/module
|
||||
$1.constantize
|
||||
loaded = $1.constantize
|
||||
|
||||
raise unless $1 == loaded.name
|
||||
|
||||
# if it is an IO we need to go back to read the object
|
||||
source.rewind if source.respond_to?(:rewind)
|
||||
retry
|
||||
|
|
|
@ -64,6 +64,17 @@ class MarshalTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "when one constant resolves to another" do
|
||||
class Parent; C = Class.new; end
|
||||
class Child < Parent; C = Class.new; end
|
||||
|
||||
dump = Marshal.dump(Child::C.new)
|
||||
|
||||
Child.send(:remove_const, :C)
|
||||
|
||||
assert_raise(ArgumentError) { Marshal.load(dump) }
|
||||
end
|
||||
|
||||
test "that a real missing class is causing an exception" do
|
||||
dumped = nil
|
||||
with_autoloading_fixtures do
|
||||
|
|
Loading…
Reference in a new issue