HappenLee commented on code in PR #56648:
URL: https://github.com/apache/doris/pull/56648#discussion_r2438790104


##########
be/src/vec/functions/function_string.cpp:
##########
@@ -1009,35 +1012,39 @@ struct UnHexImpl {
                          ColumnUInt8::Container* null_map_data) {
         auto rows_count = offsets.size();
         dst_offsets.resize(rows_count);
-        std::array<char, string_hex::MAX_STACK_CIPHER_LEN> stack_buf;
-        std::vector<char> heap_buf;
+
+        int64_t total_size = 0;
+        for (size_t i = 0; i < rows_count; i++) {
+            size_t len = offsets[i] - offsets[i - 1];
+            total_size += len / 2;
+        }
+        ColumnString::check_chars_length(total_size, rows_count);
+        dst_data.resize(total_size);
+        char* dst_data_ptr = reinterpret_cast<char*>(dst_data.data());
+        size_t offset = 0;
+
         for (int i = 0; i < rows_count; ++i) {
             const auto* source = reinterpret_cast<const char*>(&data[offsets[i 
- 1]]);
             ColumnString::Offset srclen = offsets[i] - offsets[i - 1];
 
-            if (srclen == 0) {
-                StringOP::push_null_string(i, dst_data, dst_offsets, 
*null_map_data);
+            if (UNLIKELY(srclen == 0)) {
+                (*null_map_data)[i] = 1;
+                dst_offsets[i] = cast_set<uint32_t>(offset);
                 continue;
             }
 
-            auto cipher_len = srclen / 2;
-            char* dst = nullptr;
-            if (cipher_len <= stack_buf.size()) {
-                dst = stack_buf.data();
-            } else {
-                heap_buf.resize(cipher_len);
-                dst = heap_buf.data();
-            }
+            int outlen = string_hex::hex_decode(source, srclen, dst_data_ptr + 
offset);

Review Comment:
   This operation is very risky — if you can’t guarantee that the allocated 
memory size is always larger than what the computation requires, it may lead to 
memory issues.



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