forked from OSchip/llvm-project
[Bitcode] Add fuzzer for bitcode reading
Inspired by the discussion on D118694, this adds a straightforward fuzzer for bitcode reading. Currently it will very quickly run into OOM, because we do unconditional vector reservations with user-provided sizes.
This commit is contained in:
parent
1831cbd9d4
commit
82ef888fbf
|
@ -0,0 +1,6 @@
|
|||
set(LLVM_LINK_COMPONENTS
|
||||
BitReader
|
||||
)
|
||||
add_llvm_fuzzer(llvm-dis-fuzzer
|
||||
llvm-dis-fuzzer.cpp
|
||||
)
|
|
@ -0,0 +1,26 @@
|
|||
//===-- llvm-dis-fuzzer.cpp - Fuzzer for llvm-dis using lib/Fuzzer --------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Fuzzer for LLVM bitcode reading.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Bitcode/BitcodeReader.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
LLVMContext Context;
|
||||
auto Buffer = MemoryBuffer::getMemBuffer(
|
||||
StringRef(reinterpret_cast<const char *>(Data), Size), "Fuzzer input",
|
||||
/*RequiresNullTerminator=*/false);
|
||||
consumeError(
|
||||
parseBitcodeFile(Buffer->getMemBufferRef(), Context).takeError());
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue