diff --git a/cpp/src/parquet/encoding.cc b/cpp/src/parquet/encoding.cc index e3460144fc1..2639c3dd4aa 100644 --- a/cpp/src/parquet/encoding.cc +++ b/cpp/src/parquet/encoding.cc @@ -2105,22 +2105,33 @@ class DeltaBitPackDecoder : public DecoderImpl, virtual public TypedDecoder(sizeof(T) * 8); + void InitHeader() { - if (!decoder_.GetVlqInt(&values_per_block_)) ParquetException::EofException(); - if (!decoder_.GetVlqInt(&mini_blocks_per_block_)) ParquetException::EofException(); - if (!decoder_.GetVlqInt(&total_value_count_)) { + if (!decoder_.GetVlqInt(&values_per_block_) || + !decoder_.GetVlqInt(&mini_blocks_per_block_) || + !decoder_.GetVlqInt(&total_value_count_) || + !decoder_.GetZigZagVlqInt(&last_value_)) { ParquetException::EofException(); } - if (!decoder_.GetZigZagVlqInt(&last_value_)) ParquetException::EofException(); - delta_bit_widths_ = AllocateBuffer(pool_, mini_blocks_per_block_); + if (values_per_block_ == 0) { + throw ParquetException("cannot have zero value per block"); + } + if (mini_blocks_per_block_ == 0) { + throw ParquetException("cannot have zero miniblock per block"); + } values_per_mini_block_ = values_per_block_ / mini_blocks_per_block_; + if (values_per_mini_block_ == 0) { + throw ParquetException("cannot have zero value per miniblock"); + } if (values_per_mini_block_ % 32 != 0) { throw ParquetException( "the number of values in a miniblock must be multiple of 32, but it's " + std::to_string(values_per_mini_block_)); } + delta_bit_widths_ = AllocateBuffer(pool_, mini_blocks_per_block_); block_initialized_ = false; values_current_mini_block_ = 0; } @@ -2134,6 +2145,9 @@ class DeltaBitPackDecoder : public DecoderImpl, virtual public TypedDecoder(1, bit_width_data + i)) { ParquetException::EofException(); } + if (bit_width_data[i] > kMaxDeltaBitWidth) { + throw ParquetException("delta bit width larger than integer bit width"); + } } mini_block_idx_ = 0; delta_bit_width_ = bit_width_data[0]; diff --git a/testing b/testing index 896d05d3516..2c29a733ac2 160000 --- a/testing +++ b/testing @@ -1 +1 @@ -Subproject commit 896d05d35163168831876b0f3e76977f6f20d4f4 +Subproject commit 2c29a733ac2c8492d5df3b74ea5ab1a32f892f60