From 28a705d3c7724ff3f37e5ee4256ba9b3c17cccaa Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 3 Mar 2021 23:17:34 +0000 Subject: Lagom/Fuzzers: Add fuzzers for LibCompess Adds fuzzers for Deflate, Gzip and Zlib. --- Meta/Lagom/Fuzzers/CMakeLists.txt | 3 +++ Meta/Lagom/Fuzzers/FuzzDeflate.cpp | 34 ++++++++++++++++++++++++++++++++++ Meta/Lagom/Fuzzers/FuzzGzip.cpp | 34 ++++++++++++++++++++++++++++++++++ Meta/Lagom/Fuzzers/FuzzZlib.cpp | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 Meta/Lagom/Fuzzers/FuzzDeflate.cpp create mode 100644 Meta/Lagom/Fuzzers/FuzzGzip.cpp create mode 100644 Meta/Lagom/Fuzzers/FuzzZlib.cpp diff --git a/Meta/Lagom/Fuzzers/CMakeLists.txt b/Meta/Lagom/Fuzzers/CMakeLists.txt index b0b27afcd3..4b1fa5b18b 100644 --- a/Meta/Lagom/Fuzzers/CMakeLists.txt +++ b/Meta/Lagom/Fuzzers/CMakeLists.txt @@ -16,9 +16,11 @@ function(add_simple_fuzzer name) endfunction() add_simple_fuzzer(FuzzBMPLoader) +add_simple_fuzzer(FuzzDeflate) add_simple_fuzzer(FuzzELF) add_simple_fuzzer(FuzzGemini) add_simple_fuzzer(FuzzGIFLoader) +add_simple_fuzzer(FuzzGzip) add_simple_fuzzer(FuzzICOLoader) add_simple_fuzzer(FuzzJPGLoader) add_simple_fuzzer(FuzzPNGLoader) @@ -35,6 +37,7 @@ add_simple_fuzzer(FuzzTTF) add_simple_fuzzer(FuzzURL) add_simple_fuzzer(FuzzRSAKeyParsing) add_simple_fuzzer(FuzzWAVLoader) +add_simple_fuzzer(FuzzZlib) if (NOT ENABLE_OSS_FUZZ) set(CMAKE_EXE_LINKER_FLAGS "${ORIGINAL_CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") diff --git a/Meta/Lagom/Fuzzers/FuzzDeflate.cpp b/Meta/Lagom/Fuzzers/FuzzDeflate.cpp new file mode 100644 index 0000000000..1add55efb1 --- /dev/null +++ b/Meta/Lagom/Fuzzers/FuzzDeflate.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + auto result = Compress::DeflateDecompressor::decompress_all(ReadonlyBytes { data, size }); + return result.has_value(); +} diff --git a/Meta/Lagom/Fuzzers/FuzzGzip.cpp b/Meta/Lagom/Fuzzers/FuzzGzip.cpp new file mode 100644 index 0000000000..4e8f1a0791 --- /dev/null +++ b/Meta/Lagom/Fuzzers/FuzzGzip.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + auto result = Compress::GzipDecompressor::decompress_all(ReadonlyBytes { data, size }); + return result.has_value(); +} diff --git a/Meta/Lagom/Fuzzers/FuzzZlib.cpp b/Meta/Lagom/Fuzzers/FuzzZlib.cpp new file mode 100644 index 0000000000..5d9931a627 --- /dev/null +++ b/Meta/Lagom/Fuzzers/FuzzZlib.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, the SerenityOS developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + auto result = Compress::Zlib::decompress_all(ReadonlyBytes { data, size }); + return result.has_value(); +} -- cgit v1.2.3