bryancall commented on code in PR #13671:
URL: https://github.com/apache/trafficserver/pull/13671#discussion_r3997489352
##########
src/tsutil/Regex.cc:
##########
@@ -330,6 +390,14 @@ Regex::Regex(Regex const &other)
if (other_code != nullptr) {
// Use PCRE2's built-in function to deep copy the compiled pattern
auto *copied_code = pcre2_code_copy(other_code);
+
+ // pcre2_code_copy() does not carry the machine code the JIT produced,
because that
+ // code is position dependent. Without this the copy would match on the
interpreter:
+ // same answers, much slower, and a different set of resource limits, so a
pattern
+ // that reports a JIT stack limit through the original would quietly match
through
+ // the copy. Compile it again, exactly as Regex::compile() does for a new
pattern.
+ pcre2_jit_compile(copied_code, PCRE2_JIT_COMPLETE);
+
_Code::set(_code, copied_code);
Review Comment:
Fixed in 4355035f6d. The man page agrees: pcre2_code_copy() returns NULL if
it cannot obtain memory. The copy constructor now checks it and leaves the
object empty when the copy fails, which is the state a default constructed
Regex is in and the one empty() reports, rather than holding a null pattern or
handing it to pcre2_jit_compile().
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]