github-actions[bot] commented on code in PR #66788:
URL: https://github.com/apache/doris/pull/66788#discussion_r3793842065


##########
be/src/util/hyperscan_util.cpp:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/hyperscan_util.h"
+
+#include <re2/re2.h>
+#include <re2/stringpiece.h>
+
+#include <charconv>
+#include <string>
+
+namespace doris {
+namespace {
+
+bool is_larger_than_fifty(std::string_view str) {
+    int number = 0;
+    auto [_, error] = std::from_chars(str.data(), str.data() + str.size(), 
number);
+    return error == std::errc() && number > 50;
+}
+
+std::string mask_escaped_characters_and_character_classes(std::string_view 
regexp) {
+    std::string masked_regexp(regexp);
+    bool escaped = false;
+    bool in_character_class = false;
+    bool character_class_can_close = false;
+    bool character_class_can_negate = false;
+    for (char& masked_character : masked_regexp) {
+        const char current = masked_character;
+        if (escaped) {
+            masked_character = ' ';
+            escaped = false;
+            if (in_character_class) {
+                character_class_can_close = true;
+                character_class_can_negate = false;
+            }
+            continue;
+        }
+        if (current == '\\') {
+            masked_character = ' ';
+            escaped = true;
+            continue;
+        }
+        if (in_character_class) {
+            masked_character = ' ';
+            if (current == ']' && character_class_can_close) {
+                in_character_class = false;
+            } else if (current == '^' && character_class_can_negate) {
+                character_class_can_negate = false;
+            } else {
+                character_class_can_close = true;
+                character_class_can_negate = false;
+            }
+            continue;
+        }
+        if (current == '[') {

Review Comment:
   [P1] Do not let comment text hide a later bounded repeat
   
   For `(?# [)(ab?c?d){1000,5000}`, this loop enters character-class mode at 
the `[` even though Hyperscan treats everything through `)` as a comment. With 
no later `]`, it blanks the actual `{1000,5000}`, so 
`is_hyperscan_regexp_expensive()` returns false and every shared compiler 
caller still passes the expensive repeat to Hyperscan. This is distinct from 
the existing `(?# note{51})` thread: that case is a false interception; here 
comment text creates a false negative that defeats the guard. Recognize 
Hyperscan comment contexts before changing class state and cover the shared 
entry points.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to