带环视和原子分组的正则表达式的带记忆化高效匹配(扩展版)
Efficient Matching with Memoization for Regexes with Look-around and Atomic Grouping (Extended Version)
AI总结:
针对带环视和原子分组的扩展正则表达式回溯匹配易出现灾难性回溯引发ReDoS漏洞的问题,提出基于记忆化且优化表范围的线性时间匹配算法,经真实正则实验验证具备性能优势。
摘要:
正则表达式(regex)匹配是众多应用中的基础功能,在Web服务中尤为重要。然而,回溯式匹配因实际性能与向后兼容性被绝大多数现实实现采用,却可能遭遇所谓的灾难性回溯问题,导致回溯次数呈超线性增长,引发众所周知的ReDoS(正则表达式拒绝服务)漏洞。受Davis等人近期提出的可对(非扩展)正则表达式实现线性时间运行的算法启发,我们研究了带两种常见扩展——即环视(look-around)和原子分组(atomic grouping)——的正则表达式的高效回溯匹配方法。我们提出了适用于这类扩展正则表达式的线性时间回溯匹配算法,其效率依赖记忆化机制,与Davis等人的算法类似;我们还通过精细裁剪记忆化表的范围,力求缩小其体积。我们使用了若干带上述扩展的现实世界正则表达式开展实验,结果证实了我们算法的性能优势。
英文摘要:
Regular expression (regex) matching is fundamental in many applications, especially in web services. However, matching by backtracking -- preferred by most real-world implementations for its practical performance and backward compatibility -- can suffer from so-called catastrophic backtracking, which makes the number of backtracking super-linear and leads to the well-known ReDoS vulnerability. Inspired by a recent algorithm by Davis et al. that runs in linear time for (non-extended) regexes, we study efficient backtracking matching for regexes with two common extensions, namely look-around and atomic grouping. We present linear-time backtracking matching algorithms for these extended regexes. Their efficiency relies on memoization, much like the one by Davis et al.; we also strive for smaller memoization tables by carefully trimming their range. Our experiments -- we used some real-world regexes with the aforementioned extensions -- confirm the performance advantage of our algorithms.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。