From e2ec8f6584c20b782b395441cdf8cce7ff711d1e Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Fri, 19 May 2023 02:01:34 +0200 Subject: Fuzzers: Add a fuzzer for roundtrip LZMA compression/decompression --- Meta/Lagom/Fuzzers/CMakeLists.txt | 1 + Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp (limited to 'Meta') diff --git a/Meta/Lagom/Fuzzers/CMakeLists.txt b/Meta/Lagom/Fuzzers/CMakeLists.txt index 06e650a5c6..9142ced919 100644 --- a/Meta/Lagom/Fuzzers/CMakeLists.txt +++ b/Meta/Lagom/Fuzzers/CMakeLists.txt @@ -36,6 +36,7 @@ add_simple_fuzzer(FuzzICCProfile LibGfx) add_simple_fuzzer(FuzzICOLoader LibGfx) add_simple_fuzzer(FuzzJPEGLoader LibGfx) add_simple_fuzzer(FuzzLzmaDecompression LibArchive LibCompress) +add_simple_fuzzer(FuzzLzmaRoundtrip LibCompress) add_simple_fuzzer(FuzzMatroskaReader LibVideo) add_simple_fuzzer(FuzzMD5 LibCrypto) add_simple_fuzzer(FuzzMP3Loader LibAudio) diff --git a/Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp b/Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp new file mode 100644 index 0000000000..e10c102417 --- /dev/null +++ b/Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023, Tim Schumacher . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) +{ + AllocatingMemoryStream stream {}; + + auto compressor = MUST(Compress::LzmaCompressor::create_container(MaybeOwned { stream }, {})); + MUST(compressor->write_until_depleted({ data, size })); + MUST(compressor->flush()); + + auto decompressor = MUST(Compress::LzmaDecompressor::create_from_container(MaybeOwned { stream })); + auto result = MUST(decompressor->read_until_eof()); + + VERIFY((ReadonlyBytes { data, size }) == result.span()); + + return 0; +} -- cgit v1.2.3