mirror of
https://github.com/google/brotli.git
synced 2024-11-24 12:30:15 +00:00
Convert fuzz/*.cc to C
This commit is contained in:
parent
8544ae858d
commit
bc9e7d04f1
@ -4,18 +4,19 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <brotli/decode.h>
|
||||
|
||||
// Entry point for LibFuzzer.
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
size_t addend = 0;
|
||||
if (size > 0)
|
||||
addend = data[size - 1] & 7;
|
||||
const uint8_t* next_in = data;
|
||||
|
||||
const int kBufferSize = 1024;
|
||||
uint8_t* buffer = new uint8_t[kBufferSize];
|
||||
uint8_t* buffer = (uint8_t*)malloc(sizeof(uint8_t) * kBufferSize);
|
||||
/* The biggest "magic number" in brotli is 16MiB - 16, so no need to check
|
||||
the cases with much longer output. */
|
||||
const size_t total_out_limit = (addend == 0) ? (1 << 26) : (1 << 24);
|
||||
@ -48,6 +49,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
}
|
||||
|
||||
BrotliDecoderDestroyInstance(state);
|
||||
delete[] buffer;
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
void LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
|
||||
int main(int argc, char* *argv) {
|
||||
if (argc != 2) {
|
@ -2,7 +2,6 @@
|
||||
set -e
|
||||
|
||||
export CC=${CC:-cc}
|
||||
export CXX=${CXX:-c++}
|
||||
|
||||
BROTLI="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
|
||||
SRC=$BROTLI/c
|
||||
@ -13,12 +12,12 @@ rm -rf bin
|
||||
mkdir bin
|
||||
cd bin
|
||||
|
||||
cmake $BROTLI -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" \
|
||||
cmake $BROTLI -DCMAKE_C_COMPILER="$CC" \
|
||||
-DBUILD_TESTING=OFF -DENABLE_SANITIZER=address
|
||||
make -j$(nproc) brotlidec-static
|
||||
|
||||
${CXX} -o run_decode_fuzzer -std=c++11 -fsanitize=address -I$SRC/include \
|
||||
$SRC/fuzz/decode_fuzzer.cc $SRC/fuzz/run_decode_fuzzer.cc \
|
||||
${CC} -o run_decode_fuzzer -std=c99 -fsanitize=address -I$SRC/include \
|
||||
$SRC/fuzz/decode_fuzzer.c $SRC/fuzz/run_decode_fuzzer.c \
|
||||
./libbrotlidec-static.a ./libbrotlicommon-static.a
|
||||
|
||||
mkdir decode_corpora
|
||||
|
Loading…
Reference in New Issue
Block a user