Issue #16041 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN to 2.5: UNKNOWN, 2.6: REQUIRED

I accidentally backported 53e9908d8a with this issue. I'll backport additional fixes.

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

* Author: mame (Yusuke Endoh)
* Status: Closed
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.5: UNKNOWN, 2.6: REQUIRED
----------------------------------------
```
$ 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>