emkornfield commented on a change in pull request #11710:
URL: https://github.com/apache/arrow/pull/11710#discussion_r750998396
##########
File path: cpp/src/parquet/encoding.cc
##########
@@ -2401,24 +2413,31 @@ class DeltaByteArrayDecoder : public DecoderImpl,
reinterpret_cast<const int32_t*>(buffered_prefix_length_->data()) +
prefix_len_offset_;
for (int i = 0; i < max_values; ++i) {
- data_size += prefix_len_ptr[i] + buffer[i].len;
+ if (AddWithOverflow(data_size, prefix_len_ptr[i], &data_size) ||
+ AddWithOverflow(data_size, buffer[i].len, &data_size)) {
+ throw ParquetException("excess expansion in DELTA_BYTE_ARRAY");
+ }
}
PARQUET_THROW_NOT_OK(buffered_data_->Resize(data_size));
+ string_view prefix{last_value_};
uint8_t* data_ptr = buffered_data_->mutable_data();
for (int i = 0; i < max_values; ++i) {
- DCHECK_LE(static_cast<const size_t>(prefix_len_ptr[i]),
last_value_.length());
- memcpy(data_ptr, last_value_.data(), prefix_len_ptr[i]);
+ if (ARROW_PREDICT_FALSE(static_cast<size_t>(prefix_len_ptr[i]) >
prefix.length())) {
+ throw ParquetException("prefix length too large");
+ }
+ memcpy(data_ptr, prefix.data(), prefix_len_ptr[i]);
+ // buffer[i] currently points to the string suffix
memcpy(data_ptr + prefix_len_ptr[i], buffer[i].ptr, buffer[i].len);
buffer[i].ptr = data_ptr;
buffer[i].len += prefix_len_ptr[i];
data_ptr += buffer[i].len;
- last_value_ =
- std::string(reinterpret_cast<const char*>(buffer[i].ptr),
buffer[i].len);
+ prefix = string_view{reinterpret_cast<const char*>(buffer[i].ptr),
buffer[i].len};
}
prefix_len_offset_ += max_values;
this->num_values_ -= max_values;
num_valid_values_ -= max_values;
+ last_value_ = prefix.to_string();
Review comment:
nit: to_string is a non-standard extension of our vendored version. Is
there a strong reason to use it here vs std::string(prefix)?
--
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]