bryancall opened a new pull request, #13685:
URL: https://github.com/apache/trafficserver/pull/13685

   Fourth of four, split out of #13671 at review request. Independent of the 
other three;
   it touches neither the shared contexts nor the JIT stack.
   
   ### A copied `Regex` silently changed engine
   
   `pcre2_code_copy()` duplicates a compiled pattern but not the machine code 
the JIT
   produced for it, because that code is position dependent. The copy 
constructor called
   nothing else, so every copied `Regex` matched on the interpreter: the same 
answers, far
   slower, and under a different set of resource limits. A pattern that reports 
a JIT stack
   limit through the original quietly matched through a copy, which is how the 
two can
   disagree about whether a subject is acceptable at all.
   
   `plugins/experimental/maxmind_acl` copies every rule.
   
   Compile the copy for the JIT after copying it, exactly as `compile()` does 
for a new
   pattern, and describe that in the header, which called it a deep copy. 
Nothing copies a
   `Regex` on a request path; the cost is what a compile costs.
   
   `pcre2_code_copy()` also returns null when it cannot obtain memory, and the 
copy
   constructor passed that straight to `pcre2_jit_compile()`. It is checked 
now, and a failed
   copy leaves the object empty: the state a default constructed `Regex` is in 
and the one
   `empty()` reports, rather than a `Regex` holding a null pattern.
   
   The `pcre2_jit_compile()` result is deliberately not checked, for the same 
reason
   `compile()` does not check it. A pattern the JIT declines still matches 
correctly on the
   interpreter, this class has no way to tell a caller which engine it got, and 
"no JIT" is
   not a single error code across PCRE2 versions and build options. Reporting 
the engine
   belongs to the replacement API in #13663.
   
   ### Tests
   
   Four sections asserting the property that matters: a copy answers the same 
as its
   original on a subject sized past the JIT stack bound, through the copy 
constructor, copy
   assignment, a copy of a copy, and on an ordinary subject that simply matches.
   
   Built against the unfixed implementation the original returns the stack 
limit error and
   the copy returns a match. The test needs no knowledge of whether the build 
has a JIT,
   because without one both sides agree.
   
   ### Verification
   
   Fedora 44, gcc 16.2.1, PCRE2 10.47. `[Regex]` clean under AddressSanitizer 
with UBSan.
   


-- 
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]

Reply via email to