Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
PARQUET-1333: [C++] Reading of files with dictionary size 0 fails on …
Browse files Browse the repository at this point in the history
…Windows with bad_alloc

The call with size 0 ends up in arrows memory_pool, https://github.com/apache/arrow/blob/884474ca5ca1b8da55c0b23eb7cb784c2cd9bdb4/cpp/src/arrow/memory_pool.cc#L50, and the according allocation fails. See according documentation, https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc. Only happens on Windows environment, as posix_memalign seems to handle 0 inputs in unix environments.

Author: Philipp Hoch <p.hoch@celonis.com>

Closes #472 from philhoch/bugfix-cover-empty-dicitionary-size-on-windows and squashes the following commits:

0be10bc [Philipp Hoch] account for total_size being 0, as _alligned_malloc with size 0 raises error on Windows environment
  • Loading branch information
hochphil authored and Deepak Majeti committed Jun 28, 2018
1 parent ac5bd82 commit d9c262a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/parquet/encoding-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ inline void DictionaryDecoder<ByteArrayType>::SetDict(
for (int i = 0; i < num_dictionary_values; ++i) {
total_size += dictionary_[i].len;
}
PARQUET_THROW_NOT_OK(byte_array_data_->Resize(total_size, false));
int offset = 0;
if (total_size > 0) {
PARQUET_THROW_NOT_OK(byte_array_data_->Resize(total_size, false));
}

int offset = 0;
uint8_t* bytes_data = byte_array_data_->mutable_data();
for (int i = 0; i < num_dictionary_values; ++i) {
memcpy(bytes_data + offset, dictionary_[i].ptr, dictionary_[i].len);
Expand Down

0 comments on commit d9c262a

Please sign in to comment.