Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#24274·cudf

[BUG] Parquet Snappy decompression can consume uninitialized padded input bytes after RMM pool reuse

Author: matal-nvidiaCreated Sep 23, 2026Updated Sep 29, 2026
Labelsbug? - Needs Triage

Describe the bug The libcudf Parquet reader rounds compressed-input allocations up to BUFFER_PADDING_MULTIPLE (8 bytes), but fills only the logical byte range. The final 0–7 bytes are therefore uninitialized and can retain data from a previous allocation when an RMM pool resource is used. On GB200, the decompression backend can produce corrupted decompression result records after those dirty blocks are reused.

Steps/Code to reproduce bug

#include <cudf/column/column_factories.hpp>
#include <cudf/io/parquet.hpp>
#include <cudf/table/table.hpp>
#include <cudf/types.hpp>
#include <cudf/utilities/default_stream.hpp>

#include <rmm/cuda_stream.hpp>
#include <rmm/mr/callback_memory_resource.hpp>
#include <rmm/mr/cuda_async_memory_resource.hpp>
#include <rmm/resource_ref.hpp>

#include <cuda_runtime_api.h>

#include <atomic>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>

namespace {

constexpr cudf::size_type num_rows{100};
constexpr cudf::size_type num_columns{256};
constexpr unsigned char poison_byte{0xA5};

void check_cuda(cudaError_t status, char const* operation)
{
  if (status != cudaSuccess) {
    throw std::runtime_error(std::string{operation} + ": " + cudaGetErrorString(status));
  }
}

class poisoning_memory_resource {
 public:
  poisoning_memory_resource()
    : resource_{[](std::size_t bytes, rmm::cuda_stream_view stream, void* context) {
                  auto& self = *static_cast<poisoning_memory_resource*>(context);
                  auto* pointer = rmm::device_async_resource_ref{self.upstream_}.allocate(
                    stream, bytes, rmm::CUDA_ALLOCATION_ALIGNMENT);
                  auto const status = cudaMemsetAsync(pointer, poison_byte, bytes, stream.value());
                  if (status != cudaSuccess) {
                    rmm::device_async_resource_ref{self.upstream_}.deallocate(
                      stream, pointer, bytes, rmm::CUDA_ALLOCATION_ALIGNMENT);
                    check_cuda(status, "poison allocation");
                  }
                  return pointer;
                },
                [](void* pointer,
                   std::size_t bytes,
                   rmm::cuda_stream_view stream,
                   void* context) {
                  auto& self = *static_cast<poisoning_memory_resource*>(context);
                  rmm::device_async_resource_ref{self.upstream_}.deallocate(
                    stream, pointer, bytes, rmm::CUDA_ALLOCATION_ALIGNMENT);
                },
                this,
                this}
  {
  }

  [[nodiscard]] rmm::device_async_resource_ref get() { return resource_; }

 private:
  rmm::mr::cuda_async_memory_resource upstream_;
  rmm::mr::callback_memory_resource resource_;
};

void write_snappy_file(std::string const& path)
{
  auto const stream = cudf::get_default_stream();
  std::vector<std::unique_ptr<cudf::column>> columns;
  columns.reserve(num_columns);

  for (cudf::size_type column_index = 0; column_index < num_columns; ++column_index) {
    std::vector<int32_t> host_values(num_rows);
    for (cudf::size_type row = 0; row < num_rows; ++row) {
      host_values[row] = ((row / 3) * (column_index + 3) + row % 3) % 97;
    }

    auto column = cudf::make_numeric_column(cudf::data_type{cudf::type_id::INT32},
                                            num_rows,
                                            cudf::mask_state::UNALLOCATED,
                                            stream);
    check_cuda(cudaMemcpyAsync(column->mutable_view().data<int32_t>(),
                               host_values.data(),
                               host_values.size() * sizeof(int32_t),
                               cudaMemcpyHostToDevice,
                               stream.value()),
               "copy generated column");
    columns.push_back(std::move(column));
  }
  stream.synchronize();

  cudf::table input{std::move(columns)};
  auto const options =
    cudf::io::parquet_writer_options::builder(cudf::io::sink_info{path}, input.view())
      .compression(cudf::io::compression_type::SNAPPY)
      .dictionary_policy(cudf::io::dictionary_policy::NEVER)
      .max_page_size_rows(num_rows)
      .build();
  cudf::io::write_parquet(options, stream);
  stream.synchronize();
}

int parse_positive(char const* text, char const* name)
{
  int const value = std::stoi(text);
  if (value <= 0) { throw std::invalid_argument(std::string{name} + " must be positive"); }
  return value;
}

}  // namespace

int main(int argc, char** argv)
{
  try {
    int const num_threads = argc > 1 ? parse_positive(argv[1], "threads") : 8;
    int const iterations  = argc > 2 ? parse_positive(argv[2], "iterations") : 100;
    std::string const path = argc > 3 ? argv[3] : "/tmp/cudf_snappy_padding_repro.parquet";

    check_cuda(cudaSetDevice(0), "set CUDA device");
    write_snappy_file(path);
    std::cerr << "Wrote a self-contained Snappy Parquet input to " << path << '\n';

    poisoning_memory_resource memory_resource;
    std::atomic<bool> stop{false};
    std::exception_ptr first_error;
    std::mutex error_mutex;

    auto const worker = [&](int thread_index) {
      try {
        rmm::cuda_stream stream;
        for (int iteration = 0; iteration < iterations && !stop.load(); ++iteration) {
          auto const options =
            cudf::io::parquet_reader_options::builder(cudf::io::source_info{path}).build();
          auto result = cudf::io::read_parquet(options, stream.view(), memory_resource.get());
          stream.synchronize();
          if (result.tbl->num_rows() != num_rows || result.tbl->num_columns() != num_columns) {
            throw std::runtime_error("read returned an unexpected table shape");
          }
        }
        std::cerr << "thread " << thread_index << " passed\n";
      } catch (...) {
        stop.store(true);
        std::scoped_lock guard{error_mutex};
        if (first_error == nullptr) { first_error = std::current_exception(); }
      }
    };

    std::vector<std::thread> threads;
    threads.reserve(num_threads);
    for (int thread_index = 0; thread_index < num_threads; ++thread_index) {
      threads.emplace_back(worker, thread_index);
    }
    for (auto& thread : threads) {
      thread.join();
    }
    if (first_error != nullptr) { std::rethrow_exception(first_error); }

    std::cerr << "PASS: " << num_threads << " threads x " << iterations
              << " reads with allocation poison 0xA5\n";
    return EXIT_SUCCESS;
  } catch (std::exception const& error) {
    std::cerr << "FAIL: " << error.what() << '\n';
    return EXIT_FAILURE;
  }
}

Expected behavior Parquet decompression should depend only on the logical compressed byte range and should not fail based on prior RMM allocation contents. If the decoder requires addressable padding, libcudf should initialize that padding before dispatch. Initializing at most seven bytes per datasource buffer should have negligible cost.

Environment overview (please complete the following information)

  • Environment location: bare metal
  • Method of cuDF install: built from source and injected as libcudf.so
  • GPU: NVIDIA GB200 (compute capability 10.0)
  • Driver: 580.178.04
  • Architecture: aarch64
  • CUDA toolkit: 12.9.86
  • nvCOMP: 5.3.0.0
  • Reproduced cuDF revision: v26.06.00, bcd4fb5b0304654906f6bf64473a05876d0789d2
  • Checked current main: dcf930d5b8831921aa9cfaa0e34700d6bb5704c0
  • RMM: shared pool memory resource, approximately 170.5 GiB initial pool
  • CUDA per-thread default streams enabled

Source: rapidsai/cudf

View original on GitHubView discussion on GitHub