diff options
| author | Andrii Furmanets <furmanets.andriy@gmail.com> | 2026-01-16 12:52:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-16 19:52:16 +0900 |
| commit | f872901bb263e01768ac64e6d063377c3b633e27 (patch) | |
| tree | 15d937ce883b9a1c707a241c261842e318a63077 /test | |
| parent | 16cd9daa39c5488a7ee3f60ebc6f5b3cf1ee50e4 (diff) | |
MatchData: Avoid large stack allocations in MatchData (GH-15872)
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_regexp.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 2d7a67dd54..9feababa53 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1669,6 +1669,30 @@ class TestRegexp < Test::Unit::TestCase assert_equal("hoge fuga", h["body"]) end + def test_matchdata_large_capture_groups_stack + env = {"RUBY_THREAD_MACHINE_STACK_SIZE" => (256 * 1024).to_s} + assert_separately([env], <<~'RUBY') + n = 20000 + require "rbconfig/sizeof" + stack = RubyVM::DEFAULT_PARAMS[:thread_machine_stack_size] + size = RbConfig::SIZEOF["long"] + required = (n + 1) * 4 * size + if !stack || stack == 0 || stack >= required + omit "thread machine stack size not reduced (#{stack}:#{required})" + end + + inspect = Thread.new do + str = "\u{3042}" * n + m = Regexp.new("(.)" * n).match(str) + assert_not_nil(m) + assert_equal([n - 1, n], m.offset(n)) + m.inspect + end.value + + assert_include(inspect, "MatchData") + RUBY + end + def test_regexp_popped EnvUtil.suppress_warning do assert_nothing_raised { eval("a = 1; /\#{ a }/; a") } |
