hello-stephen commented on code in PR #71098:
URL: https://github.com/apache/doris/pull/71098#discussion_r4765935099


##########
be/src/util/bit_stream_utils.inline.h:
##########
@@ -137,6 +139,52 @@ bool BitReader::GetValue(int num_bits, T* v) {
     return true;
 }
 
+template <typename T>
+size_t BitReader::GetValues(int num_bits, T* values, size_t num_values) {
+    if constexpr (std::is_same_v<T, uint8_t>) {
+        if (num_bits == 1 && num_values >= 32) {
+            return GetBitValues(num_values, values);
+        }
+    }
+    // Full-width literals are consecutive little-endian integers.
+    if (std::endian::native == std::endian::little && !std::is_same_v<T, bool> 
&&
+        num_bits == sizeof(T) * 8 && bit_offset_ % 8 == 0) {
+        const int offset = byte_offset_ + bit_offset_ / 8;
+        const size_t count = std::min(num_values, (max_bytes_ - offset) / 
sizeof(T));
+        memcpy(values, buffer_ + offset, count * sizeof(T));
+        const bool advanced = Advance(static_cast<int64_t>(count) * num_bits);

Review Comment:
   [P2] Keep backward seeks safe after a bulk read
   
   On a little-endian host, an exactly five-byte input followed by `uint8_t 
out[4]; reader.GetValues(8, out, 4); reader.SeekToBit(0);` now reads past the 
input. This `Advance(32)` leaves `(byte_offset_, bit_offset_) == (4, 0)`, so 
`SeekToBit(0)` enters `Rewind(32)` and its unconditional eight-byte `memcpy` 
reads three bytes beyond the buffer. Four scalar `GetValue(8, ...)` calls left 
`(0, 32)` and rewound without that reload. The one-bit fast path exposes the 
same issue. Please bound the rewind refill (e.g. reuse `BufferValues()`) or 
preserve the buffered-window invariant, and add a short-buffer 
bulk-read/backward-seek test. Current `RlePageDecoder` backward seeks 
reconstruct the decoder; this finding concerns the new public `BitReader` API 
composition.



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