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: d7999e9fa974
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 59c7334d0187
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 10, 2015

  1. 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 10, 2015
    Copy the full SHA
    9cdf5ad View commit details
  2. Copy the full SHA
    59c7334 View commit details
Showing with 20 additions and 1 deletion.
  1. +2 −1 kernel/common/marshal.rb
  2. +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
@@ -627,7 +627,8 @@ def construct_bignum

obj = result * sign

store_unique_object obj
add_object obj
obj
end

def construct_data
18 changes: 18 additions & 0 deletions spec/ruby/core/marshal/shared/load.rb
Original file line number Diff line number Diff line change
@@ -634,6 +634,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)