Repository: apache/arrow
File: cpp/src/parquet/arrow/fuzz_internal.cc (C++)

Code before:
    }
    // Is it a key generated by MakeEncryptionKey?
    if (key_id.starts_with(kInlineKeyPrefix)) {
      return SecureString(
          ::arrow::util::base64_decode(key_id.substr(kInlineKeyPrefix.length())));
    }
    throw ParquetException("Unknown fuzz encryption key_id");
  }
};

std::shared_ptr<DecryptionKeyRetriever> MakeKeyRetriever() {
  return std::make_shared<FuzzDecryptionKeyRetriever>();
}

namespace {

Status FuzzReadData(std::unique_ptr<FileReader> reader) {
  auto final_status = Status::OK();
  for (int i = 0; i < reader->num_row_groups(); ++i) {
    auto table_result = reader->ReadRowGroup(i);
    if (table_result.ok()) {
      // When reading returns successfully, the Arrow data should be structurally
      // valid so that it can be read normally. If that is not the case, abort
      // so that the error can be published by OSS-Fuzz.
      ARROW_CHECK_OK((*table_result)->Validate());
      final_status &= (*table_result)->ValidateFull();
    }
    final_status &= table_result.status();
  }
  return final_status;
}

template <typename DType>
Status FuzzReadTypedColumnIndex(const TypedColumnIndex<DType>* index) {
  index->min_values();
  index->max_values();
  return Status::OK();
}

Status FuzzReadColumnIndex(const ColumnIndex* index, const ColumnDescriptor* descr) {
  Status st;
  BEGIN_PARQUET_CATCH_EXCEPTIONS
  index->definition_level_histograms();
  index->repetition_level_histograms();
  index->null_pages();
  index->null_counts();
  index->non_null_page_indices();
  index->encoded_min_values();
  index->encoded_max_values();
  switch (descr->physical_type()) {
    case Type::BOOLEAN:

Review comment (suggestion):
Let's assign `*table_result`:

```suggestion
      auto table = *table_result;
      ARROW_CHECK_OK(table->Validate());
      final_status &= table->ValidateFull();
```

Code after:
    }
    // Is it a key generated by MakeEncryptionKey?
    if (key_id.starts_with(kInlineKeyPrefix)) {
      return SecureString(
          ::arrow::util::base64_decode(key_id.substr(kInlineKeyPrefix.length())));
    }
    throw ParquetException("Unknown fuzz encryption key_id");
  }
};

std::shared_ptr<DecryptionKeyRetriever> MakeKeyRetriever() {
  return std::make_shared<FuzzDecryptionKeyRetriever>();
}

namespace {

Status FuzzReadData(std::unique_ptr<FileReader> reader) {
  auto final_status = Status::OK();
  for (int i = 0; i < reader->num_row_groups(); ++i) {
    auto table_result = reader->ReadRowGroup(i);
    if (table_result.ok()) {
      // When reading returns successfully, the Arrow data should be structurally
      // valid so that it can be read normally. If that is not the case, abort
      // so that the error can be published by OSS-Fuzz.
      auto table = *table_result;
      ARROW_CHECK_OK(table->Validate());
      final_status &= table->ValidateFull();
    }
    final_status &= table_result.status();
  }
  return final_status;
}

template <typename DType>
Status FuzzReadTypedColumnIndex(const TypedColumnIndex<DType>* index) {
  index->min_values();
  index->max_values();
  return Status::OK();
}

Status FuzzReadColumnIndex(const ColumnIndex* index, const ColumnDescriptor* descr) {
  Status st;
  BEGIN_PARQUET_CATCH_EXCEPTIONS
  index->definition_level_histograms();
  index->repetition_level_histograms();
  index->null_pages();
  index->null_counts();
  index->non_null_page_indices();
  index->encoded_min_values();
  index->encoded_max_values();
  switch (descr->physical_type()) {