Skip to content

Commit 959327f

Browse files
committed
Add test + re-add explicit error check
1 parent 53de5e2 commit 959327f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cpp/src/arrow/util/rle_encoding_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,10 @@ auto RleBitPackedParser::PeekImpl(Handler&& handler) const
661661
uint32_t run_len_type = 0;
662662
const auto header_bytes =
663663
bit_util::ParseLeadingLEB128(data_, std::min(kMaxSize, data_size_), &run_len_type);
664+
if (ARROW_PREDICT_FALSE(header_bytes == 0)) {
665+
// Malformed LEB128 data
666+
return {0, ControlFlow::Break};
667+
}
664668

665669
const bool is_bit_packed = run_len_type & 1;
666670
const uint32_t count = run_len_type >> 1;

cpp/src/arrow/util/rle_encoding_test.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,32 +590,38 @@ TEST(RleBitPacked, RleBitPackedParserInvalidNonPadded) {
590590
}
591591

592592
TEST(RleBitPacked, RleBitPackedParserErrors) {
593+
using V = std::vector<uint8_t>;
594+
593595
// Truncated LEB128 header
594596
TestRleBitPackedParserError(
595597
/* bytes= */
596-
{0x81},
598+
V{0x81},
597599
/* bit_width= */ 3);
598600

599601
// Invalid LEB128 header for a 32-bit value
600602
TestRleBitPackedParserError(
601603
/* bytes= */
602-
{0xFF, 0xFF, 0xFF, 0xFF, 0x7f},
604+
V{0xFF, 0xFF, 0xFF, 0xFF, 0x7f},
603605
/* bit_width= */ 3);
604606

605607
// Zero-length repeated run
606608
TestRleBitPackedParserError(
607609
/* bytes= */
608-
{0x00},
610+
V{0x00, 0x00},
609611
/* bit_width= */ 3);
610612
TestRleBitPackedParserError(
611613
/* bytes= */
612-
{0x80, 0x00},
614+
V{0x80, 0x00, 0x00},
613615
/* bit_width= */ 3);
614616

615617
// Zero-length bit-packed run
616618
TestRleBitPackedParserError(
617619
/* bytes= */
618-
{0x01},
620+
V{0x01},
621+
/* bit_width= */ 3);
622+
TestRleBitPackedParserError(
623+
/* bytes= */
624+
V{0x80, 0x01},
619625
/* bit_width= */ 3);
620626

621627
// Bit-packed run too large

0 commit comments

Comments
 (0)