Skip to content

Commit

Permalink
apacheGH-38738: [C++] Check variadic buffer counts in bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Nov 15, 2023
1 parent 563078f commit 4104f15
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cpp/src/arrow/ipc/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ class ArrayLoader {
if (i >= static_cast<int>(variadic_counts->size())) {
return Status::IOError("variadic_count_index out of range.");
}
return static_cast<size_t>(variadic_counts->Get(i));
int64_t count = variadic_counts->Get(i);
if (count < 0 || count > std::numeric_limits<int32_t>::max()) {
return Status::IOError(
"variadic_count must be represenable as a positive int32_t, got ", count, ".");
}
return static_cast<size_t>(count);
}

Status GetFieldMetadata(int field_index, ArrayData* out) {
Expand Down Expand Up @@ -372,10 +377,10 @@ class ArrayLoader {
RETURN_NOT_OK(LoadCommon(type.id()));
RETURN_NOT_OK(GetBuffer(buffer_index_++, &out_->buffers[1]));

ARROW_ASSIGN_OR_RAISE(auto character_buffer_count,
ARROW_ASSIGN_OR_RAISE(auto data_buffer_count,
GetVariadicCount(variadic_count_index_++));
out_->buffers.resize(character_buffer_count + 2);
for (size_t i = 0; i < character_buffer_count; ++i) {
out_->buffers.resize(data_buffer_count + 2);
for (size_t i = 0; i < data_buffer_count; ++i) {
RETURN_NOT_OK(GetBuffer(buffer_index_++, &out_->buffers[i + 2]));
}
return Status::OK();
Expand Down

0 comments on commit 4104f15

Please sign in to comment.