Skip to content
Closed
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
12 changes: 9 additions & 3 deletions cpp/src/parquet/arrow/reader_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,9 @@ Status ConvertToDecimal128<FLBAType>(const Array& array,
const int32_t byte_width =
static_cast<const ::arrow::FixedSizeBinaryType&>(*fixed_size_binary_array.type())
.byte_width();
if (byte_width < kMinDecimalBytes || byte_width > kMaxDecimalBytes) {
return Status::Invalid("Invalid FIXED_LEN_BYTE_ARRAY length for Decimal128");
}

// allocate memory for the decimal array
std::shared_ptr<Buffer> data;
Expand Down Expand Up @@ -1111,8 +1114,8 @@ Status ConvertToDecimal128<ByteArrayType>(const Array& array,
int32_t record_len = 0;
const uint8_t* record_loc = binary_array.GetValue(i, &record_len);

if ((record_len < 0) || (record_len > type_length)) {
return Status::Invalid("Invalid BYTE_ARRAY size");
if (record_len < 0 || record_len > type_length) {
return Status::Invalid("Invalid BYTE_ARRAY length for Decimal128");
}

auto out_ptr_view = reinterpret_cast<uint64_t*>(out_ptr);
Expand All @@ -1121,7 +1124,10 @@ Status ConvertToDecimal128<ByteArrayType>(const Array& array,

// only convert rows that are not null if there are nulls, or
// all rows, if there are not
if (((null_count > 0) && !binary_array.IsNull(i)) || (null_count <= 0)) {
if ((null_count > 0 && !binary_array.IsNull(i)) || null_count <= 0) {
if (record_len <= 0) {
return Status::Invalid("Invalid BYTE_ARRAY length for Decimal128");
}
RawBytesToDecimalBytes(record_loc, record_len, out_ptr);
}
}
Expand Down
10 changes: 9 additions & 1 deletion cpp/src/parquet/column_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,14 @@ class ColumnReaderImplBase {
num_decoded_values_ = 0;
const uint8_t* buffer = page.data();

const int64_t total_levels_length =
static_cast<int64_t>(page.repetition_levels_byte_length()) +
page.definition_levels_byte_length();

if (total_levels_length > page.size()) {
throw ParquetException("Data page too small for levels (corrupt header?)");
}

if (max_rep_level_ > 0) {
repetition_level_decoder_.SetDataV2(page.repetition_levels_byte_length(),
max_rep_level_,
Expand All @@ -645,7 +653,7 @@ class ColumnReaderImplBase {
static_cast<int>(num_buffered_values_), buffer);
}

return page.repetition_levels_byte_length() + page.definition_levels_byte_length();
return total_levels_length;
}

// Get a decoder object for this page or create a new decoder if this is the
Expand Down
11 changes: 9 additions & 2 deletions cpp/src/parquet/encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ static inline int64_t ReadByteArray(const uint8_t* data, int64_t data_size,
if (len < 0) {
throw ParquetException("Invalid BYTE_ARRAY value");
}
const int64_t consumed_length = static_cast<int64_t>(4 + len);
const int64_t consumed_length = static_cast<int64_t>(len) + 4;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-)

if (ARROW_PREDICT_FALSE(data_size < consumed_length)) {
ParquetException::EofException();
}
Expand Down Expand Up @@ -1480,7 +1480,11 @@ class DictDecoderImpl : public DecoderImpl, virtual public DictDecoder<Type> {

void SetData(int num_values, const uint8_t* data, int len) override {
num_values_ = num_values;
if (len == 0) return;
if (len == 0) {
// Initialize dummy decoder to avoid crashes later on
idx_decoder_ = arrow::util::RleDecoder(data, len, /*bit_width=*/1);
return;
}
uint8_t bit_width = *data;
if (ARROW_PREDICT_FALSE(bit_width >= 64)) {
throw ParquetException("Invalid or corrupted bit_width");
Expand Down Expand Up @@ -2331,6 +2335,9 @@ template <typename DType>
void ByteStreamSplitDecoder<DType>::SetData(int num_values, const uint8_t* data,
int len) {
DecoderImpl::SetData(num_values, data, len);
if (num_values * static_cast<int64_t>(sizeof(T)) > len) {
throw ParquetException("Data size too small for number of values (corrupted file?)");
}
num_values_in_buffer_ = num_values;
}

Expand Down
30 changes: 28 additions & 2 deletions cpp/src/parquet/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,39 @@
#if defined(PARQUET_USE_BOOST_REGEX)
#include <boost/regex.hpp> // IWYU pragma: keep
using ::boost::regex;
using ::boost::regex_match;
using ::boost::smatch;

template <typename... Args>
static bool regex_match(Args&&... args) {
try {
return boost::regex_match(std::forward<Args>(args)...);
} catch (const boost::regex_error& e) {
if (e.code() == boost::regex_constants::error_complexity ||
e.code() == boost::regex_constants::error_stack) {
// Input-dependent error => return as if matching failed
return false;
}
throw;
}
}
#else
#include <regex>
using ::std::regex;
using ::std::regex_match;
using ::std::smatch;

template <typename... Args>
static bool regex_match(Args&&... args) {
try {
return std::regex_match(std::forward<Args>(args)...);
} catch (const std::regex_error& e) {
if (e.code() == std::regex_constants::error_complexity ||
e.code() == std::regex_constants::error_stack) {
// Input-dependent error => return as if matching failed
return false;
}
throw;
}
}
#endif

namespace parquet {
Expand Down
2 changes: 1 addition & 1 deletion testing
Submodule testing updated 20 files
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-4890562181464064
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-4899358320623616
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5104438567239680
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5166462995267584
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5191952833445888
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5633048948506624
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5639431718699008
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5663528385249280
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5665152419758080
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5670235492581376
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5683528215035904
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5689850864074752.fuzz
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5691277162315776
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5697144926502912.fuzz
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5706704584179712
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5737320855896064
+ − data/parquet/fuzzing/clusterfuzz-testcase-minimized-parquet-arrow-fuzz-5749399310565376
+ − data/parquet/fuzzing/clusterfuzz-testcase-parquet-arrow-fuzz-5694968720261120
+ − data/parquet/fuzzing/clusterfuzz-testcase-parquet-arrow-fuzz-5763056434151424.fuzz
+ − data/parquet/fuzzing/clusterfuzz-testcase-parquet-arrow-fuzz-6193345128038400