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

[Enhancement]reserve size before reading strings (backport #54713) #54743

Open
wants to merge 1 commit into
base: branch-3.4
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions be/src/formats/parquet/encoding_plain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "column/column.h"
#include "column/column_helper.h"
#include "common/status.h"
#include "formats/parquet/encoding.h"
#include "gutil/strings/substitute.h"
Expand Down Expand Up @@ -173,18 +174,21 @@ class PlainDecoder<Slice> final : public Decoder {
slices.reserve(count);

size_t num_decoded = 0;
size_t byte_size = 0;
while (num_decoded < count && _offset < _data.size) {
uint32_t length = decode_fixed32_le(reinterpret_cast<const uint8_t*>(_data.data) + _offset);
_offset += sizeof(int32_t);
slices.emplace_back(_data.data + _offset, length);
_offset += length;
byte_size += length;
num_decoded++;
}
// never happend
if (num_decoded < count || _offset > _data.size) {
return Status::InternalError(strings::Substitute(
"going to read out-of-bounds data, offset=$0,count=$1,size=$2", _offset, count, _data.size));
}
ColumnHelper::get_binary_column(dst)->reserve(count, byte_size);
auto ret = dst->append_strings(slices);
if (UNLIKELY(!ret)) {
return Status::InternalError("PlainDecoder append strings to column failed");
Expand Down
Loading