|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include <cstdint> |
| 19 | +#include <memory> |
| 20 | + |
| 21 | +#include "arrow/buffer.h" |
| 22 | +#include "arrow/csv/reader.h" |
| 23 | +#include "arrow/io/interfaces.h" |
| 24 | +#include "arrow/io/memory.h" |
| 25 | +#include "arrow/status.h" |
| 26 | +#include "arrow/table.h" |
| 27 | +#include "arrow/util/macros.h" |
| 28 | + |
| 29 | +namespace arrow::csv { |
| 30 | + |
| 31 | +Status FuzzCsvReader(const uint8_t* data, int64_t size) { |
| 32 | + auto io_context = arrow::io::default_io_context(); |
| 33 | + |
| 34 | + auto read_options = ReadOptions::Defaults(); |
| 35 | + // Make chunking more likely |
| 36 | + read_options.block_size = 4096; |
| 37 | + auto parse_options = ParseOptions::Defaults(); |
| 38 | + auto convert_options = ConvertOptions::Defaults(); |
| 39 | + convert_options.auto_dict_encode = true; |
| 40 | + |
| 41 | + auto input_stream = |
| 42 | + std::make_shared<::arrow::io::BufferReader>(std::make_shared<Buffer>(data, size)); |
| 43 | + |
| 44 | + // TODO test other reader types |
| 45 | + ARROW_ASSIGN_OR_RAISE(auto table_reader, |
| 46 | + TableReader::Make(io_context, input_stream, read_options, |
| 47 | + parse_options, convert_options)); |
| 48 | + ARROW_ASSIGN_OR_RAISE(auto table, table_reader->Read()); |
| 49 | + RETURN_NOT_OK(table->ValidateFull()); |
| 50 | + return Status::OK(); |
| 51 | +} |
| 52 | + |
| 53 | +} // namespace arrow::csv |
| 54 | + |
| 55 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 56 | + auto status = arrow::csv::FuzzCsvReader(data, static_cast<int64_t>(size)); |
| 57 | + ARROW_UNUSED(status); |
| 58 | + return 0; |
| 59 | +} |
0 commit comments