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

B

Brian Marick

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:in
`load'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
`open'
/Users/marick/src/timeclock/timeclock/server/marshal-test.rb:31:in
`load'
/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
(e-mail address removed), (e-mail address removed)
www.testing.com, www.visibleworkings.com
 
J

Joel VanderWerf

Brian said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top