add ipc-fuzzing-test

This commit is contained in:
Marco Neumann committed 2018-02-02 13:39:27 +01:00
1 parent 25a9273cb8
commit 312d8d2056
4 files changed
+88

No files matched your search

+11
View File
@@ -147,6 +147,10 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
"Build the Arrow CPython extensions"
OFF)
option(ARROW_FUZZING
"Build Arrow Fuzzing executables"
OFF)
option(ARROW_SSE3
"Build Arrow with SSE3"
ON)
@@ -249,6 +253,10 @@ if(NOT ARROW_BUILD_BENCHMARKS)
set(NO_BENCHMARKS 1)
endif()
if (NOT ARROW_FUZZING)
set(NO_FUZZING 1)
endif()
if(ARROW_HDFS)
set(ARROW_BOOST_HEADER_ONLY 0)
else()
@@ -300,6 +308,9 @@ if ("${COMPILER_FAMILY}" STREQUAL "clang")
endif()
# ASAN / TSAN / UBSAN
if(ARROW_FUZZING)
set(ARROW_USE_COVERAGE ON)
endif()
include(san-config)
# For any C code, use the same flags.
+31
View File
@@ -347,3 +347,34 @@ function(ARROW_TEST_LINK_LIBRARIES REL_TEST_NAME)
target_link_libraries(${TEST_NAME} ${ARGN})
endfunction()
############################################################
# Fuzzing
############################################################
# Add new fuzzing test executable.
#
# The single source file must define a function:
# extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
#
# No main function must be present within the source file!
#
function(ADD_ARROW_FUZZING REL_FUZZING_NAME)
if(NO_FUZZING)
return()
endif()
if (ARROW_BUILD_STATIC)
set(FUZZ_LINK_LIBS arrow_static)
else()
set(FUZZ_LINK_LIBS arrow_shared)
endif()
add_executable(${REL_FUZZING_NAME} "${REL_FUZZING_NAME}.cc")
target_link_libraries(${REL_FUZZING_NAME} ${FUZZ_LINK_LIBS})
target_compile_options(${REL_FUZZING_NAME}
PRIVATE "-fsanitize=fuzzer")
set_target_properties(${REL_FUZZING_NAME}
PROPERTIES
LINK_FLAGS "-fsanitize=fuzzer")
endfunction()
+2
View File
@@ -117,3 +117,5 @@ if (ARROW_BUILD_UTILITIES)
endif()
ADD_ARROW_BENCHMARK(ipc-read-write-benchmark)
ADD_ARROW_FUZZING(ipc-fuzzing-test)
+44
View File
@@ -0,0 +1,44 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include <memory>
#include <arrow/buffer.h>
#include <arrow/io/memory.h>
#include <arrow/ipc/reader.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
arrow::Status status;
auto buffer = std::make_shared<arrow::Buffer>(data, size);
arrow::io::BufferReader buffer_reader(buffer);
std::shared_ptr<arrow::ipc::RecordBatchReader> batch_reader;
status = arrow::ipc::RecordBatchStreamReader::Open(&buffer_reader, &batch_reader);
if (!status.ok()) {
return 0;
}
std::shared_ptr<arrow::RecordBatch> batch;
do {
status = batch_reader->ReadNext(&batch);
if (!status.ok()) {
return 0;
}
} while (batch);
return 0;
}