Fuzzers: Add a fuzzer for roundtrip LZMA compression/decompression

This commit is contained in:
Tim Schumacher 2023-05-19 02:01:34 +02:00 committed by Jelle Raaijmakers
parent a01968ee6d
commit e2ec8f6584
Notes: sideshowbarker 2024-07-16 23:55:09 +09:00
2 changed files with 25 additions and 0 deletions

View file

@ -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)

View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2023, Tim Schumacher <timschumi@gmx.de>.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/MemoryStream.h>
#include <LibCompress/Lzma.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
AllocatingMemoryStream stream {};
auto compressor = MUST(Compress::LzmaCompressor::create_container(MaybeOwned<Stream> { stream }, {}));
MUST(compressor->write_until_depleted({ data, size }));
MUST(compressor->flush());
auto decompressor = MUST(Compress::LzmaDecompressor::create_from_container(MaybeOwned<Stream> { stream }));
auto result = MUST(decompressor->read_until_eof());
VERIFY((ReadonlyBytes { data, size }) == result.span());
return 0;
}