diff options
Diffstat (limited to 'test/ruby/test_marshal.rb')
-rw-r--r-- | test/ruby/test_marshal.rb | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index 19f41de27e..79d9577737 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -1,6 +1,5 @@ # frozen_string_literal: false require 'test/unit' -require 'tempfile' require_relative 'marshaltestlib' class TestMarshal < Test::Unit::TestCase @@ -33,7 +32,7 @@ class TestMarshal < Test::Unit::TestCase end def test_marshal - a = [1, 2, 3, [4,5,"foo"], {1=>"bar"}, 2.5, fact(30)] + a = [1, 2, 3, 2**32, 2**64, [4,5,"foo"], {1=>"bar"}, 2.5, fact(30)] assert_equal a, Marshal.load(Marshal.dump(a)) [[1,2,3,4], [81, 2, 118, 3146]].each { |w,x,y,z| @@ -47,6 +46,26 @@ class TestMarshal < Test::Unit::TestCase } end + def test_marshal_integers + a = [] + [-2, -1, 0, 1, 2].each do |i| + 0.upto(65).map do |exp| + a << 2**exp + i + end + end + assert_equal a, Marshal.load(Marshal.dump(a)) + + a = [2**32, []]*2 + assert_equal a, Marshal.load(Marshal.dump(a)) + + a = [2**32, 2**32, []]*2 + assert_equal a, Marshal.load(Marshal.dump(a)) + end + + def test_marshal_small_bignum_backref + assert_equal [2**32, 2**32], Marshal.load("\x04\b[\al+\b\x00\x00\x00\x00\x01\x00@\x06") + end + StrClone = String.clone def test_marshal_cloned_class assert_instance_of(StrClone, Marshal.load(Marshal.dump(StrClone.new("abc")))) @@ -72,6 +91,14 @@ class TestMarshal < Test::Unit::TestCase TestMarshal.instance_eval { remove_const :StructInvalidMembers } end + def test_load_range_as_struct + assert_raise(TypeError, 'GH-6832') do + # Can be obtained with: + # $ ruby -e 'Range = Struct.new(:a, :b, :c); p Marshal.dump(Range.new(nil, nil, nil))' + Marshal.load("\x04\bS:\nRange\b:\x06a0:\x06b0:\x06c0") + end + end + class C def initialize(str) @str = str @@ -286,11 +313,10 @@ class TestMarshal < Test::Unit::TestCase assert_equal(c, Marshal.load(Marshal.dump(c)), bug2109) assert_nothing_raised(ArgumentError, '[ruby-dev:40386]') do - re = Tempfile.create("marshal_regexp") do |f| - f.binmode.write("\x04\bI/\x00\x00\x06:\rencoding\"\rUS-ASCII") - f.rewind - re2 = Marshal.load(f) - re2 + re = IO.pipe do |r, w| + w.write("\x04\bI/\x00\x00\x06:\rencoding\"\rUS-ASCII") + # Marshal.load would not overread and block + Marshal.load(r) end assert_equal(//, re) end @@ -583,6 +609,8 @@ class TestMarshal < Test::Unit::TestCase def test_continuation EnvUtil.suppress_warning {require "continuation"} + omit 'requires callcc support' unless respond_to?(:callcc) + c = Bug9523.new assert_raise_with_message(RuntimeError, /Marshal\.dump reentered at marshal_dump/) do Marshal.dump(c) @@ -922,7 +950,7 @@ class TestMarshal < Test::Unit::TestCase end def test_modules_and_classes_are_not_frozen - objects = Marshal.load(encode([Object, Kernel]), freeze: true) + _objects = Marshal.load(encode([Object, Kernel]), freeze: true) refute_predicate Object, :frozen? refute_predicate Kernel, :frozen? end |