Fuzzers: Add a fuzzer for roundtrip LZMA compression/decompression
This commit is contained in:
parent
a01968ee6d
commit
e2ec8f6584
Notes:
sideshowbarker
2024-07-16 23:55:09 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/e2ec8f6584 Pull-request: https://github.com/SerenityOS/serenity/pull/18920 Reviewed-by: https://github.com/gmta ✅
2 changed files with 25 additions and 0 deletions
Meta/Lagom/Fuzzers
|
@ -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)
|
||||
|
|
24
Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp
Normal file
24
Meta/Lagom/Fuzzers/FuzzLzmaRoundtrip.cpp
Normal 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;
|
||||
}
|
Loading…
Add table
Reference in a new issue