Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SortBuffer batchSize computation overflow #10848

Closed
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
3 changes: 1 addition & 2 deletions velox/exec/SortBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,8 @@ void SortBuffer::spillOutput() {
void SortBuffer::prepareOutput(vector_size_t maxOutputRows) {
VELOX_CHECK_GT(maxOutputRows, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

maxOutputRows may be used as batchSize, we need to convert it to vector_size_t as check, to make sure it's less than 0x7fffffff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will create a separate PR to solve it, it involves much refactor

VELOX_CHECK_GT(numInputRows_, numOutputRows_);

const vector_size_t batchSize =
std::min<vector_size_t>(numInputRows_ - numOutputRows_, maxOutputRows);
std::min<uint64_t>(numInputRows_ - numOutputRows_, maxOutputRows);
if (output_ != nullptr) {
VectorPtr output = std::move(output_);
BaseVector::prepareForReuse(output, batchSize);
Expand Down
4 changes: 2 additions & 2 deletions velox/exec/SortBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class SortBuffer {
// sort buffer object.
bool noMoreInput_ = false;
// The number of received input rows.
size_t numInputRows_ = 0;
uint64_t numInputRows_ = 0;
// Used to store the input data in row format.
std::unique_ptr<RowContainer> data_;
std::vector<char*> sortedRows_;
Expand All @@ -123,7 +123,7 @@ class SortBuffer {
// 'data_->estimateRowSize()' across all accumulated data set.
std::optional<uint64_t> estimatedOutputRowSize_{};
// The number of rows that has been returned.
size_t numOutputRows_{0};
uint64_t numOutputRows_{0};
};

} // namespace facebook::velox::exec
Loading