Project

General

Profile

Actions

Bug #16041

closed

eval's path argument seems to trigger GC bug

Added by mame (Yusuke Endoh) over 5 years ago. Updated about 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
[ruby-core:94122]

Description

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

@nobu (Nobuyoshi Nakada) @ko1 (Koichi Sasada) can you debug?


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #15916: Memory leak in Regexp literal interpolationClosedActions

Updated by mame (Yusuke Endoh) over 5 years ago

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)
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Related to Bug #15916: Memory leak in Regexp literal interpolation added
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Assigned to Closed

Applied in changeset git|5931857281ce45c1c277aa86d1588119ab00a955.


Fix dangling path name from fstring

  • parse.y (yycompile): make sure in advance that the __FILE__
    object shares a fstring, to get rid of dangling path name.
    Fixed up 53e9908d8afc7f03109b0aafd1698ab35f512b05. [Bug #16041]

  • vm_eval.c (eval_make_iseq): ditto.

Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

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

Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

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

ruby_2_6 r67736 merged revision(s) 5931857281ce45c1c277aa86d1588119ab00a955,76e2370f132f83c16c9de39a0a9356579f364527.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0