[#97319] [Ruby master Feature#16667] Allow parameters to Symbol#to_proc and Method#to_proc — jgomo3@...

Issue #16667 has been reported by jgomo3 (Jes俍 Gez).

10 messages 2020/03/01

[#97344] [Ruby master Feature#16670] Reverse order of `expression` in `pattern` for 1-line pattern matching while it's still experimental — ttilberg@...

Issue #16670 has been reported by ttilberg (Tim Tilberg).

9 messages 2020/03/03

[#97355] [Ruby master Misc#16671] BASERUBY version policy — ko1@...

Issue #16671 has been reported by ko1 (Koichi Sasada).

10 messages 2020/03/04

[#97359] [Ruby master Bug#16672] net/http leaves original content-length header intact after inflating response — justin.reid@...

Issue #16672 has been reported by jmreid (Justin Reid).

15 messages 2020/03/04

[#97390] [Ruby master Bug#16677] Negative integer powered (**) to a float number results in a complex — camille.drapier@...

Issue #16677 has been reported by CamilleDrapier (Camille Drapier).

25 messages 2020/03/07

[#97410] [Ruby master Bug#16680] [Breaking Change] Ruby 2.7 not support symlinks folder in $LOAD_PATH to work with autoload. — vil963@...

Issue #16680 has been reported by zw963 (Wei Zheng).

8 messages 2020/03/07

[#97416] [Ruby master Bug#16682] Ruby 2.7.0p0 crash on exit if there is an active RUBY_INTERNAL_EVENT_GC_EXIT tracepoint — jean.boussier@...

Issue #16682 has been reported by byroot (Jean Boussier).

16 messages 2020/03/09

[#97448] [Ruby master Feature#16688] Allow #to_path object as argument to system() — daniel@...42.com

Issue #16688 has been reported by Dan0042 (Daniel DeLorme).

12 messages 2020/03/11

[#97528] [Ruby master Misc#16693] DevelopersMeeting20200410Japan — mame@...

Issue #16693 has been reported by mame (Yusuke Endoh).

12 messages 2020/03/16

[#97536] [Ruby master Bug#16694] JIT vs hardened GCC with PCH — v.ondruch@...

Issue #16694 has been reported by vo.x (Vit Ondruch).

11 messages 2020/03/18

[#97538] [Ruby master Bug#16695] Stack consistency error when using the return value — s.wakeup31@...

Issue #16695 has been reported by s4ichi (takamasa saichi).

10 messages 2020/03/18

[#97554] [Ruby master Bug#16697] Hash.ruby2_keywords_hash?(value) should support any object — eregontp@...

Issue #16697 has been reported by Eregon (Benoit Daloze).

12 messages 2020/03/19

[#97609] [Ruby master Bug#16740] Deprecating and removing the broken Process.clock_getres — eregontp@...

Issue #16740 has been reported by Eregon (Benoit Daloze).

14 messages 2020/03/28

[#97621] [Ruby master Bug#16743] problem with multi threading [BUG] Segmentation fault — pauloo.jansen@...

Issue #16743 has been reported by paulorja (paulo jansen).

12 messages 2020/03/29

[#97629] [Ruby master Feature#16744] Flag to load current bundle without using bundle exec — headius@...

Issue #16744 has been reported by headius (Charles Nutter).

11 messages 2020/03/30

[ruby-core:97631] [Ruby master Bug#15968] Custom marshal_load methods allow object instance variables to "leak" into other objects

From: usa@...
Date: 2020-03-30 21:21:58 UTC
List: ruby-core #97631
Issue #15968 has been updated by usa (Usaku NAKAMURA).

Backport changed from 2.4: REQUIRED, 2.5: REQUIRED, 2.6: DONE to 2.4: REQUIRED, 2.5: DONE, 2.6: DONE

ruby_2_5 r67861 merged revision(s) c9423b016cfeab852bc5a829e55e0a11f80b3ab7,0b1e26398e018116180bf41cb63887f77d5d1b82,78ee2c245331e353e218b8fac9ca722a2bcd8fea.

----------------------------------------
Bug #15968: Custom marshal_load methods allow object instance variables to "leak" into other objects
https://bugs.ruby-lang.org/issues/15968#change-84824

* Author: alipman (Aaron Lipman)
* Status: Closed
* Priority: Normal
* ruby -v: 2.6.3
* Backport: 2.4: REQUIRED, 2.5: DONE, 2.6: DONE
----------------------------------------
While working on a Rails app, I noticed some odd behavior where after marshalling and demarshalling an array of ActiveRecord objects, some elements were replaced with symbols and empty hashes ([original Rails bug report](https://github.com/rails/rails/issues/36522)).

It appears some of Rails' custom marshallization methods modify allow an object's unset instance variables to be set during marshallization. However, since these instance variables weren't counted at the start of marshallization, they overflow into subsequent array elements upon demarshallization.

Here is a test case (written in plain Ruby) demonstrating this behavior:

```ruby
require 'test/unit'

class Foo
  attr_accessor :bar, :baz

  def initialize
    self.bar = Bar.new(self)
  end
end

class Bar
  attr_accessor :foo

  def initialize(foo)
    self.foo = foo
  end

  def marshal_dump
    self.foo.baz = :problem
    {foo: self.foo}
  end

  def marshal_load(data)
    self.foo = data[:foo]
  end
end

class BugTest < Test::Unit::TestCase
  def test_marshalization
    foo = Foo.new
    array = [foo, nil]
    marshalled_array = Marshal.dump(array)
    demarshalled_array = Marshal.load(marshalled_array)

    assert_nil demarshalled_array[1]
  end
end
```

I'm not positive this qualifies as a bug - if a programmer writes custom `marshal_dump` and `marshal_load` methods, perhaps it's their responsibility to avoid unintended side-effects like those demonstrated in my test case.

However, I think this issue might be altogether avoided by adding a reserved delimiter character to Ruby's core marshallization functionality (in marshal.c) representing the "end" of a serialized object. For instance, in the above test case, `marshalled_array` comes out to:

```
\x04\b[\ao:\bFoo\x06:\t@barU:\bBar{\x06:\bfoo@\x06:\t@baz:\fproblem0
```

Suppose Ruby used a `z` character to represent the end of a serialized object - in this case, `marshalled_array` would come out to something like:

```
\x04\b[\ao:\bFoo\x06:\t@barU:\bBar{\x06:\bfoo@\x06:\t@baz:\fproblemz0
```

(Note the second-to-last character - `z`.)

This way, when demarshalling an object, even if additional instance variables had somehow snuck in during marshallization process, the `z` character could be used to mark the end of a serialized object, ensuring that the extra instance variables don't overflow into the next segment of serialized data.

I don't write much C, and I haven't fully grokked Ruby's marshal.c - so there may be dozens of reasons why this won't work. But I think a serialization strategy along those lines may help avoid unexpected behavior.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next