Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
mislav opened this Issue Jan 18, 2012 · 4 comments

Comments

Projects
None yet
4 participants
Contributor

mislav commented Jan 18, 2012

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'
Contributor

mislav commented Jan 18, 2012

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.

Contributor

drbrain commented Jan 18, 2012

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

Contributor

henrikhodne commented Jan 19, 2012

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

@hosiawak hosiawak closed this in 7b116c6 Jan 20, 2012

Member

hosiawak commented Jan 20, 2012

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 added a commit to lostisland/faraday_middleware that referenced this issue Apr 17, 2014

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.

mislav added a commit to lostisland/faraday_middleware that referenced this issue Apr 19, 2014

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment