Issue #13223 has been updated by Eregon (Benoit Daloze).


shyouhei (Shyouhei Urabe) wrote:
> I'd personally like to vote for ignoring redefinitions of constants. In general redefinitions prevent optimizations.  That doesn't make me happy.

I agree in that it is good to not change basic functionality such as File.join based on some global state.

Redefinition of constants is part of Ruby though.
With a JIT, the assumption that constants do not change can be embedded with the existence of the JIT'd code itself,
and deoptimize if the value change. Therefore redefinition of constants has no cost in compiled code, unless they are frequently changed.

Overall I think these decisions should not be based only on performance concerns,
especially in this case where the performance of File.join is likely insignificantly changed by looking up the constant.

----------------------------------------
Bug #13223: `File.join` will segv if File::SEPARATOR and File::Separator are set.
https://bugs.ruby-lang.org/issues/13223#change-63631

* Author: tenderlovemaking (Aaron Patterson)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-02-17 trunk 57648) [x86_64-darwin16]
* Backport: 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONTNEED
----------------------------------------
The program below will crash with a segv:

~~~ruby
File.const_set :Separator, "hello"
File.const_set :SEPARATOR, "hello"

GC.start

File.join "hello", "world"
~~~

This is because the separator object is referenced from a global variable and setting the constants allows the object to be GC'd and the global will go bad.

I've attached a patch that contains a test to demonstrate the problem along with a fix.

---Files--------------------------------
0001-Fix-segv-in-File.join-when-SEPARATOR-and-Separator-a.patch (3.04 KB)


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