[ruby-core:94123] [Ruby master Bug#16041] eval's path argument seems to trigger GC bug

From: mame@...
Date: 2019-08-03 01:57:30 UTC
List: ruby-core #94123
Issue #16041 has been updated by mame (Yusuke Endoh).


It could reproduce with simpler bug.rb:

```
file = "1.rb"
eval(File.read(file), nil, File.expand_path(file))
eval(File.read(file), nil, File.expand_path(file))
```

```
$ ~/work/ruby/miniruby bug.rb 
Traceback (most recent call last):
	3: from bug.rb:3:in `<main>'
	2: from bug.rb:3:in `eval'
	1: from :1:in `<main>'
:1:in `require_relative': path name contains null byte (ArgumentError)
```

----------------------------------------
Bug #16041: eval's path argument seems to trigger GC bug
https://bugs.ruby-lang.org/issues/16041#change-80370

* Author: mame (Yusuke Endoh)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
```
$ pwd
/tmp/bug-0123456789

$ cat bug.rb 
require "pathname"

file = "1.rb"
path = Pathname.new(file)
eval(File.read(file), nil, path.expand_path.to_s)

file2 = Dir["1.rb"].first
p file == file2 #=> true
path = Pathname.new(file2) # if it is Pathname.new(file), it works gracefully
eval(File.read(file), nil, path.expand_path.to_s)

$ cat 1.rb 
require_relative '2'
__FILE__

$ cat 2.rb 

$ ~/work/ruby/local/bin/ruby -v
ruby 2.7.0dev (2019-08-02T14:01:54Z master 247b06d400) [x86_64-linux]

$ ~/work/ruby/local/bin/ruby bug.rb 
true
Traceback (most recent call last):
	3: from bug.rb:10:in `<main>'
	2: from bug.rb:10:in `eval'
	1: from 鐃緒申YmV:1:in `<main>'
鐃緒申YmV:1:in `require_relative': path name contains null byte (ArgumentError)
```

As you see, the backtrace contains broken bytes.

Notes:

* If `Pathname.new(file2)` is replaced with `Pathname.new(file)`, it works without an error.  But `file == file2` evaluates to true.
* The directory `/tmp/bug-0123456789` is important to reproduce the issue.  If it is shorter, you cannot repro.  I guess it is related to whether the path string is embedded or not.
* This issue was originally caused in [bundler](https://github.com/bundler/bundler/issues/7271).

@nobu @ko1 can you debug?



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