Skip to content

Commit ed536d1

Browse files
authored
GH-50149: [C++][Parquet] Avoid process abort when encoding fuzzer encounters OOM (#50150)
### Rationale for this change In the Parquet encoding fuzzer, an OOM error when trying to roundtrip the encoding payload leads to a hard error that is reported as an issue on OSS-Fuzz. This should be converted to a soft error, i.e. a potential log message but not a process abort. ### Are these changes tested? By additional fuzz regression file as well as manually. ### Are there any user-facing changes? No. * GitHub Issue: #50149 Authored-by: Antoine Pitrou <antoine@python.org> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 2f5dc41 commit ed536d1

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

cpp/src/parquet/arrow/fuzz_encoding_internal.cc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,24 @@ struct TypedFuzzEncoding {
290290
}
291291

292292
// Re-encode and re-decode using roundtrip encoding
293-
{
294-
auto compare_chunk = [&](int offset, std::span<const c_type> chunk_values) {
295-
return CompareChunkAgainstReference(offset, chunk_values);
296-
};
293+
auto compare_chunk = [&](int offset, std::span<const c_type> chunk_values) {
294+
return CompareChunkAgainstReference(offset, chunk_values);
295+
};
296+
auto do_roundtrip = [&]() -> Status {
297297
auto encoder = MakeEncoder(roundtrip_encoding_);
298298
BEGIN_PARQUET_CATCH_EXCEPTIONS
299299
if constexpr (arrow_supported()) {
300300
encoder->Put(*reference_array_);
301301
auto reencoded_buffer = encoder->FlushValues();
302302
auto reencoded_data = reencoded_buffer->template span_as<uint8_t>();
303-
auto array = DecodeArrow(roundtrip_encoding_, reencoded_data).ValueOrDie();
304-
ARROW_CHECK_OK(array->ValidateFull());
305-
ARROW_CHECK_OK(CompareAgainstReference(array));
303+
ARROW_ASSIGN_OR_RAISE(auto array,
304+
DecodeArrow(roundtrip_encoding_, reencoded_data));
305+
RETURN_NOT_OK(array->ValidateFull());
306+
RETURN_NOT_OK(CompareAgainstReference(array));
306307
// Compare with reading raw values
307308
for (const int chunk_size : chunk_sizes()) {
308-
ARROW_CHECK_OK(RunOnDecodedChunks(roundtrip_encoding_, reencoded_data,
309-
chunk_size, compare_chunk));
309+
RETURN_NOT_OK(RunOnDecodedChunks(roundtrip_encoding_, reencoded_data,
310+
chunk_size, compare_chunk));
310311
}
311312
} else {
312313
encoder->Put(reference_values_.data(),
@@ -315,14 +316,19 @@ struct TypedFuzzEncoding {
315316
auto reencoded_data = reencoded_buffer->template span_as<uint8_t>();
316317
// Vary chunk sizes
317318
for (const int chunk_size : chunk_sizes()) {
318-
ARROW_CHECK_OK(RunOnDecodedChunks(roundtrip_encoding_, reencoded_data,
319-
chunk_size, compare_chunk));
319+
RETURN_NOT_OK(RunOnDecodedChunks(roundtrip_encoding_, reencoded_data,
320+
chunk_size, compare_chunk));
320321
}
321322
}
322323
END_PARQUET_CATCH_EXCEPTIONS
324+
return Status::OK();
325+
};
326+
Status roundtrip_status = do_roundtrip();
327+
// OOM when attempting to roundtrip is not a hard failure, any other error is.
328+
if (!roundtrip_status.IsOutOfMemory()) {
329+
ARROW_CHECK_OK(roundtrip_status);
323330
}
324-
325-
return Status::OK();
331+
return roundtrip_status;
326332
}
327333

328334
protected:

0 commit comments

Comments
 (0)