mrhhsg commented on code in PR #68244:
URL: https://github.com/apache/doris/pull/68244#discussion_r4056443587


##########
be/src/util/jsonb_utils.h:
##########
@@ -162,7 +162,9 @@ class JsonbToJson {
             return;
         }
         char char_buffer[16];
-        for (const char* ptr = str; ptr != str + len && *ptr; ++ptr) {
+        // A JSON string may legally contain U+0000, so the loop must be 
bounded by
+        // the length only; the NUL itself is escaped as \u0000 by the default 
branch.
+        for (const char* ptr = str; ptr != str + len; ++ptr) {

Review Comment:
   Good catch, fixed in 67d0df8.
   
   `intern_json()` now passes `getBlobLen()` for the `T_String` case, so the 
stored
   payload length reaches the length-bounded loop unchanged. `JsonbWriter` 
writes a
   string with `writeString(str, len)` and patches the size field with the exact
   number of bytes written, so it never emits NUL padding and `getBlobLen()` is 
the
   authoritative length here; the direct string path in `vjson_each.cpp` already
   relies on the same helper.
   
   New coverage for the branch you pointed at:
   
   - `JsonbParserTest.ParseJsonWithTrailingNulInString` (`{"key":"a\u0000"}`)
   - `JsonbParserTest.ParseJsonWithOnlyNulInString` (`{"key":"\u0000"}`)
   - `JsonbParserTest.ParseJsonWithTrailingNulInNestedArray` 
(`{"key":["a\u0000","\u0000"]}`)
   - regression `json_each_text_trailing_nul` and 
`explode_json_array_string_trailing_nul`
   
   The regression output regenerated on a local cluster now shows
   `["a\u0000","\u0000"]` (length 20) and `["a\u0000"]` (length 11) where the 
old
   code returned `["a",""]` and `["a"]`.
   
   Note that `JsonbStringVal::length()` has the same trimming behaviour for its
   other callers (the string equality check in `jsonb_document.h` and two spots 
in
   `function_jsonb.cpp`). Those are separate semantics from JSON 
textualization, so
   I left them out of this fix rather than widening the diff.



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