MCPcopy Create free account
hub / github.com/apache/arrow / FuzzIpcFile

Function FuzzIpcFile

cpp/src/arrow/ipc/reader.cc:2864–2980  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2862}
2863
2864Status FuzzIpcFile(const uint8_t* data, int64_t size) {
2865 auto buffer = std::make_shared<Buffer>(data, size);
2866
2867 Status final_status;
2868
2869 struct IpcReadResult {
2870 std::shared_ptr<Schema> schema;
2871 std::vector<RecordBatchWithMetadata> batches = {};
2872 ReadStats stats = {};
2873 };
2874
2875 // Try to read the IPC file as a stream to compare the results (differential fuzzing)
2876 auto do_stream_read = [&]() -> Result<IpcReadResult> {
2877 io::BufferReader buffer_reader(buffer);
2878 // Skip magic bytes at the beginning
2879 RETURN_NOT_OK(
2880 buffer_reader.Advance(bit_util::RoundUpToMultipleOf8(kArrowMagicBytes.length())));
2881 ARROW_ASSIGN_OR_RAISE(auto batch_reader, RecordBatchStreamReader::Open(
2882 &buffer_reader, FuzzingOptions()));
2883
2884 std::vector<RecordBatchWithMetadata> batches;
2885 while (true) {
2886 ARROW_ASSIGN_OR_RAISE(auto batch, batch_reader->ReadNext());
2887 if (!batch.batch && !batch.custom_metadata) {
2888 // EOS
2889 break;
2890 }
2891 RETURN_NOT_OK(ValidateFuzzBatch(batch));
2892 batches.push_back(batch);
2893 }
2894 return IpcReadResult{batch_reader->schema(), batches, batch_reader->stats()};
2895 };
2896
2897 auto do_file_read = [&](bool pre_buffer) -> Result<IpcReadResult> {
2898 io::BufferReader buffer_reader(buffer);
2899 ARROW_ASSIGN_OR_RAISE(auto batch_reader,
2900 RecordBatchFileReader::Open(&buffer_reader, FuzzingOptions()));
2901 if (pre_buffer) {
2902 // Pre-buffer all record batches
2903 RETURN_NOT_OK(batch_reader->PreBufferMetadata(/*indices=*/{}));
2904 }
2905
2906 IpcReadResult result = {.schema = batch_reader->schema()};
2907 const int n_batches = batch_reader->num_record_batches();
2908 // Delay error return until the end, as we want to access all record batches
2909 Status st;
2910 for (int i = 0; i < n_batches; ++i) {
2911 RecordBatchWithMetadata batch;
2912 st &= batch_reader->ReadRecordBatchWithCustomMetadata(i).Value(&batch);
2913 st &= ValidateFuzzBatch(batch);
2914 result.batches.push_back(batch);
2915 }
2916 RETURN_NOT_OK(st);
2917 result.stats = batch_reader->stats();
2918 return result;
2919 };
2920
2921 // Persistent read result for differential fuzzing.

Callers 1

LLVMFuzzerTestOneInputFunction · 0.85

Calls 15

RoundUpToMultipleOf8Function · 0.85
ValidateFuzzBatchFunction · 0.85
CompareFuzzBatchesFunction · 0.85
push_backMethod · 0.80
TypeErrorFunction · 0.50
InvalidFunction · 0.50
AdvanceMethod · 0.45
lengthMethod · 0.45
schemaMethod · 0.45
statsMethod · 0.45
num_record_batchesMethod · 0.45

Tested by

no test coverage detected