Fuzzers: Add fuzzer for the Tar parser

This commit is contained in:
Idan Horowitz 2022-10-16 12:25:16 +03:00
parent 9e6475d76d
commit 9f3de0be6a
2 changed files with 40 additions and 0 deletions

View file

@ -61,6 +61,7 @@ add_simple_fuzzer(FuzzSHA384 LibCrypto)
add_simple_fuzzer(FuzzSHA512 LibCrypto)
add_simple_fuzzer(FuzzShell LibShell)
add_simple_fuzzer(FuzzSQLParser LibSQL)
add_simple_fuzzer(FuzzTar LibArchive)
add_simple_fuzzer(FuzzTTF LibGfx)
add_simple_fuzzer(FuzzURL)
add_simple_fuzzer(FuzzUTF16BEDecoder LibTextCodec)

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/MemoryStream.h>
#include <LibArchive/TarStream.h>
#include <stdio.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
InputMemoryStream input_stream(ReadonlyBytes { data, size });
Archive::TarInputStream tar_stream(input_stream);
if (!tar_stream.valid())
return 0;
for (; !tar_stream.finished(); tar_stream.advance()) {
auto const& header = tar_stream.header();
if (!header.content_is_like_extended_header())
continue;
switch (header.type_flag()) {
case Archive::TarFileType::GlobalExtendedHeader:
case Archive::TarFileType::ExtendedHeader: {
auto result = tar_stream.for_each_extended_header([&](StringView, StringView) {});
if (result.is_error())
return 0;
break;
}
default:
return 0;
}
}
return 0;
}