arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2605.07289cs.DScs.CL
收藏

正则表达式中带回溯引用的匹配问题的复杂性

On the Complexity of the Matching Problem of Regular Expressions with Backreferences

CyberAgent, Inc.(CyberAgent公司);National Institute of Informatics(日本信息处理研究所)

Soh Kumabe, Yuya Uezato

AI总结:

本文研究带回溯引用的正则表达式匹配问题的细粒度复杂性,证明其在特定参数下的难解性,并提出高效的算法。

摘要:

ReDoS是一种已知的算法复杂性攻击类型,攻击者通过恶意构造的字符串耗尽正则表达式匹配引擎的计算资源。即使匹配引擎存在二次时间行为,如Stack Overflow (2016)和Cloudflare (2019)的严重故障,都引发了关于能否构造具有证明效率的匹配引擎的问题。对于经典正则表达式(REGEX),Thompson的构造方法提供了线性时间算法。然而,实际引擎支持强大的功能,如回溯引用,这严格扩展了REGEX的表达能力,但不幸增加了ReDoS攻击的风险。本文研究带回溯引用的正则表达式(REWBs)的字符串匹配问题的细粒度复杂性。具体而言,我们考虑r-use k-REWBs。在难度方面,我们证明对于k-REWBs的字符串匹配问题,无法在O(n^{2k-ε})时间内解决,即使ε>0,这在SETH假设下成立。我们还证明当参数为REWB表达式的长度时,该问题是W[2]-难的,加强了之前的W[1]-难性证明。此外,我们证明对于2-use 2-REWBs的问题,除非三角检测问题可以在相同时间内解决,否则无法在n^{1+o(1)}时间内解决。在算法方面,我们提出了一个O(n log²n)时间的算法,用于1-use REWBs,这显著优于Nogami和Terauchi (MFCS, 2025)最近的O(n²)时间算法。我们的算法采用了多种技术,包括后缀树、REGEX的转换单体、因子森林数据结构和字符串的周期性。

英文摘要:

ReDoS is a well-known type of algorithmic complexity attack, where an adversary supplies maliciously crafted strings to a regular expression matching engine, aiming to exhaust computational resources of systems. Even quadratic-time behavior in matching engines has been exploited in successful attacks, as exemplified by major outages at Stack Overflow (2016) and Cloudflare (2019). These incidents motivate a fundamental question: Is it possible to construct matching engines that are provably efficient, running in (near-)linear time in the length of the input string? For classical regular expressions (REGEX), Thompson's construction yields a linear-time algorithm. However, practical engines support powerful features such as backreferences, which strictly extend the expressive power of REGEX but unfortunately increase the risk of ReDoS attacks. This paper investigates the fine-grained complexity of the string matching problem for regular expressions with backreferences (REWBs). Specifically, we consider $r$-use $k$-REWBs. On the hardness side, we show that the string matching problem for $k$-REWBs cannot be solved in $O(n^{2k-ε})$ time for any $ε> 0$ under SETH. We also prove that this problem is \textbf{W[2]}-hard when parameterized by the length of the REWB expression, strengthening the previous \textbf{W[1]}-hardness. Moreover, we prove that this problem for $2$-use $2$-REWBs cannot be solved in $n^{1+o(1)}$ time unless the triangle detection problem can be solved in that time. On the algorithmic side, we present an $O(n \log^2 n)$-time algorithm for $1$-use REWBs, which significantly improves upon the recent $O(n^2)$-time algorithm by Nogami and Terauchi (MFCS, 2025). Our algorithm employs several techniques including suffix trees, transition monoids of REGEXes, factorization forest data structures, and periodicity of strings.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑