Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Marshal error with hash that was shrunk using `reject!` #1522

Closed
mislav opened this Issue · 4 comments

4 participants

Mislav Marohnić Eric Hodel Henrik Hodne Karol Hosiawa
Mislav Marohnić

Gather 'round folks and witness Marshal.load choke on the Incredible Shrinking Hash™!

env = { }

# first it grows:
('a'..'c').each {|k| env[k] = nil }
('A'..'Z').each {|k| env[k * 3] = "" }

Marshal.load Marshal.dump(env) # => works

# then it shrinks:
env.reject! { |k,v| !v.respond_to? :to_str }

Marshal.load Marshal.dump(env) # ERROR in rbx 1.8 mode

The error:

Exception: `ArgumentError' kernel/common/marshal.rb:469 - load error, unknown type 0
kernel/common/marshal.rb:380:in `construct'
kernel/common/marshal.rb:469:in `construct_hash'
kernel/common/integer.rb:87:in `times'
kernel/common/marshal.rb:468:in `construct_hash'
kernel/common/marshal.rb:326:in `construct'
kernel/common/marshal.rb:973:in `load'
Mislav Marohnić

I just discovered that in my code where I first found this, after the reject! I have a missing pair that wasn't supposed to be removed (the block for it yields false). So, reject! is broken in ways other than just marshaling.

Eric Hodel

Ruby can't load the dumped Hash either, it walks off the end of the Marshal stream looking for more data.

Henrik Hodne
Collaborator

@mislav If you can write how to reproduce the other issue as well (removing things that shouldn't be removed), that would be splendid!

Karol Hosiawa hosiawak closed this in 7b116c6
Karol Hosiawa
Collaborator

Hash#reject! was broken in 1.8 mode - sometimes it would delete keys that were in the same bucket that weren't supposed to be deleted. Because the keys were missing Marshall was failing.

Mislav Marohnić mislav referenced this issue from a commit in lostisland/faraday_middleware
Mislav Marohnić mislav Enable RackCompatible specs on Rubinius
It used to be that those failed because of a Rubinius bug
rubinius/rubinius#1522

But it's been 2 years since then, so assume that it's fixed.
15b62d1
Mislav Marohnić mislav referenced this issue from a commit in lostisland/faraday_middleware
Mislav Marohnić mislav Enable RackCompatible specs on Rubinius
It used to be that those failed because of a Rubinius bug
rubinius/rubinius#1522

But it's been 2 years since then, so assume that it's fixed.
1af335e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.