Marshal.load EOF on loading subclass of Array (1.8.1)

I think I have found a bug in marshaling in version “ruby 1.8.1
(2003-10-31) [powerpc-darwin]”. It’s difficult to describe in
words, but I have a failing test.

It seems to require a subclass of Array that adds an instance
variable, an object of that class, and another object that refers to
the first object. Change any of those facts, and you do not get this
failure upon loading the marshaled data:

  1. Error:
    test_marshaling(SessionTests):
    EOFError: End of file reached
    /Users/marick/src/timeclock/timeclock/server/marshal-test.rb:32:in
    load' /Users/marick/src/timeclock/timeclock/server/marshal-test.rb:32:inload’
    /Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
    open' /Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:inload’
    /Users/marick/src/timeclock/timeclock/server/marshal-test.rb:52:in
    `test_marshaling’

Here is the Test::Unit test. I hope it’s reasonably clear. It’s a
drastically stripped-down version of the original code+test.

Is this a true bug?

========== snip ================

require ‘pp’

Inherit from some user-defined class, and the test passes

class RecordList < Array
def initialize
super
@next_record_id = 0 # Delete this line, and the test passes.
end
end

class ActiveJobManager
def initialize(all_records)
@all_records = all_records # Delete this line, and the test passes
end
end

class Session
def initialize(user)
@user = user
@records = RecordList.new
# Use the following instead of the above, and the test passes.
# @records = []
@active_job_manager = ActiveJobManager.new(@records)
# Use the following instead of the above, and the test passes.
# @active_job_manager = ActiveJobManager.new([])
end

def load
@records, @active_job_manager = File.open(@user, “r”) { | f |
Marshal.load(f)
}
end

def save
File.open(@user, “w”) { | f |
Marshal.dump([@records, @active_job_manager], f)
}
end
end

class SessionTests < Test::Unit::TestCase

TEST_USER = “marshal-test-data”

def test_marshaling
File.delete(TEST_USER) if FileTest.exists?(TEST_USER)
@session = Session.new(TEST_USER)
@session.save
pp @session.load
end
end

···

Brian Marick
Consulting, training, contracting, and research
Focused on the intersection of testing, programming, and design
marick@testing.com, marick@visibleworkings.com
www.testing.com, www.visibleworkings.com

Brian Marick wrote:

I think I have found a bug in marshaling in version “ruby 1.8.1
(2003-10-31) [powerpc-darwin]”. It’s difficult to describe in
words, but I have a failing test.

Try updating to the latest stable ruby. On

ruby 1.8.1 (2003-11-22) [i686-linux]

your code has no errors.

I know that matz fixed a Marshal bug in mid November.

Yes, the latest stable Ruby fixes this. Next time I’ll try that first.

Good timing: I hope to use the code as an example at a client next week.

···

On Sunday, November 30, 2003, at 08:39 PM, Joel VanderWerf wrote:

Brian Marick wrote:

I think I have found a bug in marshaling in version “ruby 1.8.1
(2003-10-31) [powerpc-darwin]”. It’s difficult to describe in
words, but I have a failing test.

Try updating to the latest stable ruby. On

ruby 1.8.1 (2003-11-22) [i686-linux]

your code has no errors.

I know that matz fixed a Marshal bug in mid November.


Brian Marick
Consulting, training, contracting, and research
Focused on the intersection of testing, programming, and design
marick@testing.com, marick@visibleworkings.com
www.testing.com, www.visibleworkings.com