From 98bfcb4b5754948c921ed94851102883121eab5d Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 30 Aug 2020 11:51:55 +0200 Subject: [PATCH] Meta+LibGfx: Fuzz BMP parsing --- Meta/Lagom/Fuzzers/CMakeLists.txt | 9 +++++++ Meta/Lagom/Fuzzers/FuzzBMP.cpp | 41 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Meta/Lagom/Fuzzers/FuzzBMP.cpp diff --git a/Meta/Lagom/Fuzzers/CMakeLists.txt b/Meta/Lagom/Fuzzers/CMakeLists.txt index cec56eccb603cd..a52bb14723a0b1 100644 --- a/Meta/Lagom/Fuzzers/CMakeLists.txt +++ b/Meta/Lagom/Fuzzers/CMakeLists.txt @@ -1,3 +1,12 @@ +add_executable(FuzzBMP FuzzBMP.cpp) +target_compile_options(FuzzBMP + PRIVATE $<$:-g -O1 -fsanitize=fuzzer> + ) +target_link_libraries(FuzzBMP + PUBLIC Lagom + PRIVATE $<$:-fsanitize=fuzzer> + ) + add_executable(FuzzELF FuzzELF.cpp) target_compile_options(FuzzELF PRIVATE $<$:-g -O1 -fsanitize=fuzzer> diff --git a/Meta/Lagom/Fuzzers/FuzzBMP.cpp b/Meta/Lagom/Fuzzers/FuzzBMP.cpp new file mode 100644 index 00000000000000..40ebd227843bdd --- /dev/null +++ b/Meta/Lagom/Fuzzers/FuzzBMP.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020, 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) +{ + Gfx::BMPImageDecoderPlugin loader { data, size }; + auto bitmap = loader.bitmap(); + if (!bitmap) + return 1; + if (bitmap->width() >= 100000 || bitmap->height() >= 100000) { + fprintf(stderr, "Silly bitmap: %dx%d pixels?!\n", bitmap->width(), bitmap->height()); + ASSERT_NOT_REACHED(); + } + return 0; +}