sahvx655-wq commented on code in PR #64091:
URL: https://github.com/apache/doris/pull/64091#discussion_r3504078720


##########
be/src/util/decompressor.cpp:
##########
@@ -552,10 +552,12 @@ Status Lz4BlockDecompressor::decompress(uint8_t* input, 
uint32_t input_len,
                 break;
             }
 
-            // Decompress this block.
+            // Decompress this block. Capacity must track output_ptr: 
remaining_output_len
+            // is fixed per large block while output_ptr advances per small 
block.
             auto decompressed_small_block_len = LZ4_decompress_safe(
                     reinterpret_cast<const char*>(input_ptr), 
reinterpret_cast<char*>(output_ptr),
-                    compressed_small_block_len, remaining_output_len);
+                    compressed_small_block_len,
+                    cast_set<uint32_t>(output_max_len - (output_ptr - 
output)));

Review Comment:
   Added be/test/util/lz4_block_decompressor_test.cpp, mirroring the Snappy 
one. The regression case builds an LZ4BLOCK stream with two small blocks inside 
a single large block and an output buffer sized to hold only the first (64 
bytes for two 40-byte blocks). The declared large-block length is set to 64 so 
the outer need-more-output check passes and execution reaches the inner loop; 
the first small block advances output_ptr, and the second must be decompressed 
against the remaining capacity. With the stale full-block capacity that second 
call would write past output_max_len; with the fix it gets the real remaining 
space, LZ4_decompress_safe returns an error, and decompress returns 
InvalidArgument. The test asserts st.ok() is false there, so it goes red on the 
pre-fix code and green after.
   
   I also added a well-formed two-small-block round-trip so the happy path 
stays covered. Picked up automatically by the util/*.cpp glob in 
be/test/CMakeLists.txt, so no build wiring needed.



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