Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ include(ThirdpartyToolchain)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARROW_CXXFLAGS}")

message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

if ("${COMPILER_FAMILY}" STREQUAL "clang")
# Using Clang with ccache causes a bunch of spurious warnings that are
# purportedly fixed in the next version of ccache. See the following for details:
Expand All @@ -305,7 +303,7 @@ endif()

# ASAN / TSAN / UBSAN
if(ARROW_FUZZING)
set(ARROW_USE_COVERAGE ON)
set(ARROW_USE_COVERAGE ON)
endif()
include(san-config)

Expand Down Expand Up @@ -333,6 +331,9 @@ if ("${ARROW_GENERATE_COVERAGE}")
endif()
endif()

# CMAKE_CXX_FLAGS now fully assembled
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")

# set compile output directory
string (TOLOWER ${CMAKE_BUILD_TYPE} BUILD_SUBDIR_NAME)

Expand Down
25 changes: 24 additions & 1 deletion cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ and benchmarks or `make runbenchmark` to run only the benchmark tests.

Benchmark logs will be placed in the build directory under `build/benchmark-logs`.

## Building/Running fuzzers
### Testing with LLVM AddressSanitizer

To use AddressSanitizer (ASAN) to find bad memory accesses or leaks with LLVM,
pass `-DARROW_USE_ASAN=ON` when building. You must use clang to compile with
ASAN, and `ARROW_USE_ASAN` is mutually-exclusive with the valgrind option
`ARROW_TEST_MEMCHECK`.

### Building/Running fuzzers

Fuzzers can help finding unhandled exceptions and problems with untrusted input that
may lead to crashes, security issues and undefined behavior. They do this by
Expand Down Expand Up @@ -128,6 +135,22 @@ stack trace as well as the input data. After a problem was found this way, it sh
be reported and fixed. Usually, the fuzzing process cannot be continued until the
fix is applied, since the fuzzer usually converts to the problem again.

If you build fuzzers with ASAN, you need to set the `ASAN_SYMBOLIZER_PATH`
environment variable to the absolute path of `llvm-symbolizer`, which is a tool
that ships with LLVM.

```shell
export ASAN_SYMBOLIZER_PATH=$(type -p llvm-symbolizer)
```

Note that some fuzzer builds currently reject paths with a version qualifier
(like `llvm-sanitizer-5.0`). To overcome this, set an appropriate symlink
(here, when using LLVM 5.0):

```shell
ln -sf /usr/bin/llvm-sanitizer-5.0 /usr/bin/llvm-sanitizer
```

There are some problems that may occur during the compilation process:

- libfuzzer was not distributed with your LLVM: `ld: file not found: .../libLLVMFuzzer.a`
Expand Down
19 changes: 19 additions & 0 deletions cpp/build-support/lsan-suppressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

# False positive from atexit() registration in libc
leak:*__new_exitfn*
6 changes: 0 additions & 6 deletions cpp/build-support/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ function setup_sanitizers() {
# Set up suppressions for LeakSanitizer
LSAN_OPTIONS="$LSAN_OPTIONS suppressions=$ROOT/build-support/lsan-suppressions.txt"
export LSAN_OPTIONS

# Suppressions require symbolization. We'll default to using the symbolizer in
# thirdparty.
if [ -z "$ASAN_SYMBOLIZER_PATH" ]; then
export ASAN_SYMBOLIZER_PATH=$(find $NATIVE_TOOLCHAIN/llvm-3.7.0/bin -name llvm-symbolizer)
fi
}

function run_test() {
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/arrow/io/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,11 @@ Status BufferReader::Tell(int64_t* position) const {
bool BufferReader::supports_zero_copy() const { return true; }

Status BufferReader::Read(int64_t nbytes, int64_t* bytes_read, void* buffer) {
memcpy(buffer, data_ + position_, nbytes);
*bytes_read = std::min(nbytes, size_ - position_);
position_ += *bytes_read;
if (*bytes_read) {
memcpy(buffer, data_ + position_, *bytes_read);
position_ += *bytes_read;
}
return Status::OK();
}

Expand Down
16 changes: 16 additions & 0 deletions cpp/src/arrow/ipc/ipc-read-write-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -755,5 +755,21 @@ TEST_F(TestTensorRoundTrip, NonContiguous) {
CheckTensorRoundTrip(tensor);
}

TEST(TestRecordBatchStreamReader, MalformedInput) {
const std::string empty_str = "";
const std::string garbage_str = "12345678";

auto empty = std::make_shared<Buffer>(empty_str);
auto garbage = std::make_shared<Buffer>(garbage_str);

std::shared_ptr<RecordBatchReader> batch_reader;

io::BufferReader empty_reader(empty);
ASSERT_RAISES(Invalid, RecordBatchStreamReader::Open(&empty_reader, &batch_reader));

io::BufferReader garbage_reader(garbage);
ASSERT_RAISES(Invalid, RecordBatchStreamReader::Open(&garbage_reader, &batch_reader));
}

} // namespace ipc
} // namespace arrow
5 changes: 4 additions & 1 deletion cpp/src/arrow/ipc/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ Status ReadMessage(io::InputStream* file, std::unique_ptr<Message>* message) {
std::shared_ptr<Buffer> metadata;
RETURN_NOT_OK(file->Read(message_length, &metadata));
if (metadata->size() != message_length) {
return Status::IOError("Unexpected end of stream trying to read message");
std::stringstream ss;
ss << "Expected to read " << message_length << " metadata bytes, but "
<< "only read " << metadata->size();
return Status::Invalid(ss.str());
}

return Message::ReadFrom(metadata, file, message);
Expand Down