From efddc2309c5ff8a1842bea8a9c0d7d4a5d6e1e60 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 1 Apr 2026 15:01:58 -0300 Subject: Bug: wrong initialization in result from 'gmatch' Function returned by 'string.gmatch' can be left in an inconsistent state after an error. --- testes/pm.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'testes') diff --git a/testes/pm.lua b/testes/pm.lua index 720d2a35..feab33db 100644 --- a/testes/pm.lua +++ b/testes/pm.lua @@ -347,6 +347,16 @@ do -- init parameter in gmatch end +do -- bug since 5.3 + local N = 20000 + local iter = string.gmatch(string.rep("a", N), string.rep("a?", N)) + pcall(iter) -- error for pattern too complex + -- calling function again found recursion count ('matchdepth') equal + -- to -1, so it did not detect next C-stack overflow + pcall(iter) +end + + -- tests for `%f' (`frontiers') assert(string.gsub("aaa aa a aaa a", "%f[%w]a", "x") == "xaa xa x xaa x") -- cgit v1.2.3-55-g6feb