This is an automated email from the ASF dual-hosted git repository.

airborne12 pushed a commit to branch clucene
in repository https://gitbox.apache.org/repos/asf/doris-thirdparty.git


The following commit(s) were added to refs/heads/clucene by this push:
     new 08d45e541fe [fix](inverted index) reject null bytes in term middle to 
avoid stack overflow (#368)
08d45e541fe is described below

commit 08d45e541fef1e48dc4ab00d2d5fde9569b49ee3
Author: zzzxl <[email protected]>
AuthorDate: Wed Aug 26 21:25:45 2026 +0800

    [fix](inverted index) reject null bytes in term middle to avoid stack 
overflow (#368)
---
 src/core/CLucene/index/SDocumentWriter.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/core/CLucene/index/SDocumentWriter.cpp 
b/src/core/CLucene/index/SDocumentWriter.cpp
index 39ea1720d05..b4ded79b029 100644
--- a/src/core/CLucene/index/SDocumentWriter.cpp
+++ b/src/core/CLucene/index/SDocumentWriter.cpp
@@ -504,6 +504,26 @@ void 
SDocumentsWriter<T>::ThreadState::FieldData::addPosition(Token *token) {
         code = (code * 31) + tokenText[upto++];
     uint32_t hashPos = code & postingsHashMask;
 
+    if (upto < tokenTextLen) {
+        for (int32_t i = upto; i < tokenTextLen; i++) {
+            if (tokenText[i] != CLUCENE_END_OF_WORD) {
+                char error_msg[512];
+                if constexpr (std::is_same_v<T, char>) {
+                    snprintf(error_msg, sizeof(error_msg),
+                             "Inverted index does not support terms with null 
byte (\\0) in the "
+                             "middle. "
+                             "Found null at position %d, but non-null 
character at position %d. "
+                             "Term prefix: '%.*s'.",
+                             upto, i, std::min(upto, 50), tokenText);
+                } else {
+                    snprintf(error_msg, sizeof(error_msg),
+                             "Term contains null character in the middle at 
position %d.", upto);
+                }
+                _CLTHROWA(CL_ERR_IllegalArgument, error_msg);
+            }
+        }
+    }
+
     assert(!postingsCompacted);
 
     // Locate Posting in hash


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

Reply via email to