Skip to content

Object with finalizer dumps wrong data leading to: load': marshal data too short #7734

@larskanis

Description

@larskanis

Environment Information

jruby 9.4.2.0 (3.1.0) 2023-03-21 90d2913 OpenJDK 64-Bit Server VM 11.0.18+10-post-Ubuntu-0ubuntu122.04 on 11.0.18+10-post-Ubuntu-0ubuntu122.04 +jit [x86_64-linux]

Older JRubies are affected equally.

Expected Behavior

This can be done in irb:

a = ""   # => "" 
ObjectSpace.define_finalizer(a, Kernel.method(:puts))   # => [0, #<Method: Kernel.puts(*)>] 
Marshal.load(Marshal.dump(a))  # => ""

This expectation is met on MRI and on TruffleRuby.

Actual Behavior

JRuby dumps wrong marshal data when a finalizer is set on the object to be marshaled. It doesn't matter what kind of object it is or which method is set as the finalizer.

a = ""   # => "" 
ObjectSpace.define_finalizer(a, Kernel.method(:puts))   # => [0, #<Method: Kernel.puts(*)>] 
Marshal.load(Marshal.dump(a))

`org/jruby/RubyMarshal.java:149:in `load': marshal data too short (ArgumentError)
        from (irb):13:in `evaluate'                            
        from org/jruby/RubyKernel.java:1143:in `eval'          
	from org/jruby/RubyKernel.java:1586:in `loop'
	from org/jruby/RubyKernel.java:1292:in `catch'
	from org/jruby/RubyKernel.java:1292:in `catch'
	from /home/local/COMCARD-NT/kanis/.rvm/rubies/jruby-9.4.2.0/bin/irb:13:in `<main>'`

# here is the difference:
Marshal.dump(a)  # => "\x04\bI\"\x00\a:\x06ET" 
Marshal.dump("") # => "\x04\bI\"\x00\x06:\x06ET" 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions