From 11dbe1e6aa6593d964a2b6648d53502877af2fd1 Mon Sep 17 00:00:00 2001 From: Dominic Szablewski Date: Thu, 16 Dec 2021 20:02:37 +0100 Subject: [PATCH] Add clang fuzzing harness. Thanks @landaire --- qoifuzz.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 qoifuzz.c diff --git a/qoifuzz.c b/qoifuzz.c new file mode 100644 index 00000000..1b5c7929 --- /dev/null +++ b/qoifuzz.c @@ -0,0 +1,51 @@ +/* + +clang fuzzing harness for qoi_decode + +Compile and run with: + clang -fsanitize=address,fuzzer -g -O0 qoifuzz.c && ./a.out + +Dominic Szablewski - https://phoboslab.org + + +-- LICENSE: The MIT License(MIT) + +Copyright(c) 2021 Dominic Szablewski + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files(the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions : +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + + +#define QOI_IMPLEMENTATION +#include "qoi.h" +#include +#include + +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + int w, h; + if (size < 4) { + return 0; + } + + qoi_desc desc; + void* decoded = qoi_decode((void*)(data + 4), (int)(size - 4), &desc, *((int *)data)); + if (decoded != NULL) { + free(decoded); + } + return 0; +}