Skip to content

Commit

Permalink
apacheGH-38479: [C++] Avoid passing null pointer to LZ4 frame decompr…
Browse files Browse the repository at this point in the history
…essor (apache#39125)

### Rationale for this change

Avoid undefined behavior in LZ4 when adding an offset to a null pointer.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: apache#38479
  • Loading branch information
pitrou authored and dgreiss committed Feb 17, 2024
1 parent 798ca04 commit 93704bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cpp/src/arrow/io/compressed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class CompressedInputStream::Impl {
// Decompress some data from the compressed_ buffer.
// Call this function only if the decompressed_ buffer is empty.
Status DecompressData() {
DCHECK_NE(compressed_->data(), nullptr);

int64_t decompress_size = kDecompressSize;

while (true) {
Expand Down Expand Up @@ -329,7 +331,7 @@ class CompressedInputStream::Impl {
// Try to feed more data into the decompressed_ buffer.
Status RefillDecompressed(bool* has_data) {
// First try to read data from the decompressor
if (compressed_) {
if (compressed_ && compressed_->size() != 0) {
if (decompressor_->IsFinished()) {
// We just went over the end of a previous compressed stream.
RETURN_NOT_OK(decompressor_->Reset());
Expand Down
1 change: 1 addition & 0 deletions cpp/src/arrow/util/compression_lz4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class LZ4Decompressor : public Decompressor {
auto dst_capacity = static_cast<size_t>(output_len);
size_t ret;

DCHECK_NE(src, nullptr);
ret =
LZ4F_decompress(ctx_, dst, &dst_capacity, src, &src_size, nullptr /* options */);
if (LZ4F_isError(ret)) {
Expand Down

0 comments on commit 93704bd

Please sign in to comment.