Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions cpp/src/parquet/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ auto DispatchArrowBinaryHelper(typename EncodingTraits<DType>::Accumulator* acc,
}
}

void CheckPageLargeEnough(int64_t remaining_bytes, int32_t value_width,
int64_t num_values) {
if (remaining_bytes < value_width * num_values) {
ParquetException::EofException();
}
}

// Internal decoder class hierarchy

class DecoderImpl : virtual public Decoder {
Expand Down Expand Up @@ -385,9 +392,7 @@ int PlainDecoder<DType>::DecodeArrow(

constexpr int value_size = static_cast<int>(sizeof(value_type));
int values_decoded = num_values - null_count;
if (ARROW_PREDICT_FALSE(this->len_ < value_size * values_decoded)) {
ParquetException::EofException();
}
CheckPageLargeEnough(this->len_, value_size, values_decoded);

const uint8_t* data = this->data_;

Expand Down Expand Up @@ -419,9 +424,7 @@ int PlainDecoder<DType>::DecodeArrow(

constexpr int value_size = static_cast<int>(sizeof(value_type));
int values_decoded = num_values - null_count;
if (ARROW_PREDICT_FALSE(this->len_ < value_size * values_decoded)) {
ParquetException::EofException();
}
CheckPageLargeEnough(this->len_, value_size, values_decoded);

const uint8_t* data = this->data_;

Expand Down Expand Up @@ -659,9 +662,7 @@ inline int PlainDecoder<FLBAType>::DecodeArrow(
typename EncodingTraits<FLBAType>::Accumulator* builder) {
const int byte_width = this->type_length_;
const int values_decoded = num_values - null_count;
if (ARROW_PREDICT_FALSE(len_ < byte_width * values_decoded)) {
ParquetException::EofException();
}
CheckPageLargeEnough(len_, byte_width, values_decoded);

PARQUET_THROW_NOT_OK(builder->Reserve(num_values));

Expand Down Expand Up @@ -691,9 +692,7 @@ inline int PlainDecoder<FLBAType>::DecodeArrow(
typename EncodingTraits<FLBAType>::DictAccumulator* builder) {
const int byte_width = this->type_length_;
const int values_decoded = num_values - null_count;
if (ARROW_PREDICT_FALSE(len_ < byte_width * values_decoded)) {
ParquetException::EofException();
}
CheckPageLargeEnough(len_, byte_width, values_decoded);

PARQUET_THROW_NOT_OK(builder->Reserve(num_values));
PARQUET_THROW_NOT_OK(
Expand Down
Loading