From 1258a0fb90ea63bf1ec108815cce0d552acfc726 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 7 May 2020 21:49:40 +0200 Subject: [PATCH] Remove the 65 size limit for name_err_mesg_to_str MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This limit was introduced on Nov 20 1996 in 554b989ba1623b9f6a0b76f00824c83a23fbcbc1 Apparently to protect from a buffer overflow: * eval.c (f_missing): オブジェクトの文字列表現が長すぎる時バッファ を書き潰していた However I tested that path with very large strings and it works fine. --- error.c | 2 +- test/ruby/test_name_error.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/error.c b/error.c index 09d5787ad5..4912869e43 100644 --- a/error.c +++ b/error.c @@ -1791,7 +1791,7 @@ name_err_mesg_to_str(VALUE obj) d = rb_protect(rb_inspect, obj, &state); if (state) rb_set_errinfo(Qnil); - if (NIL_P(d) || RSTRING_LEN(d) > 65) { + if (NIL_P(d)) { d = rb_any_to_s(obj); } singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#'); diff --git a/test/ruby/test_name_error.rb b/test/ruby/test_name_error.rb index 102a4a67e8..ec03046c22 100644 --- a/test/ruby/test_name_error.rb +++ b/test/ruby/test_name_error.rb @@ -127,4 +127,17 @@ class TestNameError < Test::Unit::TestCase -> {require ARGV[0]}.call end; end + + def test_large_receiver_inspect + receiver = Class.new do + def self.inspect + 'A' * 120 + end + end + + error = assert_raise(NameError) do + receiver::FOO + end + assert_equal "uninitialized constant #{'A' * 120}::FOO", error.message + end end