Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 737fee60ab5d
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3c7b6018dffa
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 9, 2015

  1. Copy the full SHA
    a8494c2 View commit details
  2. Added Bignum specs for unmarshaling 32-bit Bignums on 64-bit platforms

    When a 32-bit platform marshals a Bignum, that same number may be
    unmarshaled as a Fixnum on 64-bit platforms. We need to ensure that
    it still unmarshals correctly on 64-bit platforms.
    
    We ran into the following case:
    
      val = 1433868532 # a Bignum on 32-bit platforms, Fixnum on 64-bit
      arr = [val, val]
      Marshal.dump(arr)
    
    where `arr` was being dumped by a 32-bit platform, and loaded on
    a 64-bit platform, where it threw "dump format error (unlinked)"
    because a Bignum is not an ImmediateValue but a Fixnum is.
    Since `val` is a Fixnum on 64-bit machines, it was being counted
    as an ImmediateValue, and not being added to Marshal's @objects
    table when it should have been.
    sshao committed Jun 9, 2015
    Copy the full SHA
    12a8583 View commit details
  3. Copy the full SHA
    3c7b601 View commit details
Showing with 20 additions and 11 deletions.
  1. +2 −1 kernel/common/marshal.rb
  2. +0 −10 spec/ruby/core/marshal/dump_spec.rb
  3. +18 −0 spec/ruby/core/marshal/shared/load.rb
3 changes: 2 additions & 1 deletion kernel/common/marshal.rb
Original file line number Diff line number Diff line change
@@ -507,7 +507,8 @@ def construct_bignum

obj = result * sign

store_unique_object obj
add_object obj
obj
end

def construct_data
10 changes: 0 additions & 10 deletions spec/ruby/core/marshal/dump_spec.rb
Original file line number Diff line number Diff line change
@@ -170,16 +170,6 @@
[Marshal, -2361183241434822606847, "\004\bl-\n\377\377\377\377\377\377\377\377\177\000"],
].should be_computed_by(:dump)
end

ruby_version_is "1.9" do
it "dumps a Bignum" do
[ [Marshal, 2**64, "\004\bl+\n\000\000\000\000\000\000\000\000\001\000"],
[Marshal, 2**90, "\004\bl+\v#{"\000" * 11}\004"],
[Marshal, -2**63, "\004\bl-\t\000\000\000\000\000\000\000\200"],
[Marshal, -2**64, "\004\bl-\n\000\000\000\000\000\000\000\000\001\000"],
].should be_computed_by(:dump)
end
end
end

describe "with a String" do
18 changes: 18 additions & 0 deletions spec/ruby/core/marshal/shared/load.rb
Original file line number Diff line number Diff line change
@@ -561,6 +561,24 @@
end
end

describe "for a Bignum" do
platform_is :wordsize => 64 do
context "that is Bignum on 32-bit platforms but Fixnum on 64-bit" do
it "dumps a Fixnum" do
val = Marshal.load("\004\bl+\ab:wU")
val.should == 1433877090
val.class.should == Fixnum
end

it "dumps an array containing multiple references to the Bignum as an array of Fixnum" do
arr = Marshal.load("\004\b[\al+\a\223BwU@\006")
arr.should == [1433879187, 1433879187]
arr.each { |v| v.class.should == Fixnum }
end
end
end
end

describe "for a Time" do
it "loads" do
Marshal.send(@method, Marshal.dump(Time.at(1))).should == Time.at(1)