Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion cpp/src/parquet/column_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,10 @@ void TestPrimitiveWriter<ByteArrayType>::ReadColumnFully(Compression::type compr
uint8_t* data_ptr = data.data();
for (int64_t i = 0; i < values_read_recently; i++) {
const ByteArray& value = this->values_out_ptr_[i + values_read_];
memcpy(data_ptr, value.ptr, value.len);
// Avoid calling memcpy with nullptr which is undefined behavior
if (value.len > 0) {
memcpy(data_ptr, value.ptr, value.len);
}
this->values_out_[i + values_read_].ptr = data_ptr;
data_ptr += value.len;
}
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/parquet/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,10 @@ void DictDecoderImpl<ByteArrayType>::SetDict(TypedDecoder<ByteArrayType>* dictio
uint8_t* bytes_data = byte_array_data_->mutable_data();
int32_t* bytes_offsets = byte_array_offsets_->mutable_data_as<int32_t>();
for (int i = 0; i < dictionary_length_; ++i) {
memcpy(bytes_data + offset, dict_values[i].ptr, dict_values[i].len);
// Avoid calling memcpy with nullptr which is undefined behavior
if (dict_values[i].len > 0) {
memcpy(bytes_data + offset, dict_values[i].ptr, dict_values[i].len);
}
bytes_offsets[i] = offset;
dict_values[i].ptr = bytes_data + offset;
offset += dict_values[i].len;
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/parquet/statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,10 @@ inline void TypedStatisticsImpl<ByteArrayType>::Copy(const ByteArray& src, ByteA
ResizableBuffer* buffer) {
if (dst->ptr == src.ptr) return;
PARQUET_THROW_NOT_OK(buffer->Resize(src.len, false));
std::memcpy(buffer->mutable_data(), src.ptr, src.len);
// Avoid calling memcpy with nullptr which is undefined behavior
if (src.len > 0) {
std::memcpy(buffer->mutable_data(), src.ptr, src.len);
}
Comment thread
rynewang marked this conversation as resolved.
Outdated
*dst = ByteArray(src.len, buffer->data());
}

Expand Down
5 changes: 4 additions & 1 deletion cpp/src/parquet/statistics_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ std::vector<ByteArray> TestStatistics<ByteArrayType>::GetDeepCopy(
for (const ByteArray& ba : values) {
uint8_t* ptr;
PARQUET_THROW_NOT_OK(pool->Allocate(ba.len, &ptr));
memcpy(ptr, ba.ptr, ba.len);
// Avoid calling memcpy with nullptr which is undefined behavior
if (ba.len > 0) {
memcpy(ptr, ba.ptr, ba.len);
}
copy.emplace_back(ba.len, ptr);
}
return copy;
Expand Down
Loading