blob: c508faf3d0360cd9263d771d1416466ec3a728fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*
* Copyright (c) 2022, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/NonnullOwnPtr.h>
#include <LibArchive/TarStream.h>
#include <LibCore/MemoryStream.h>
#include <LibCore/Stream.h>
#include <stdio.h>
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
auto input_stream_or_error = Core::Stream::MemoryStream::construct({ data, size });
if (input_stream_or_error.is_error())
return 0;
auto tar_stream_or_error = Archive::TarInputStream::construct(input_stream_or_error.release_value());
if (tar_stream_or_error.is_error())
return 0;
auto tar_stream = tar_stream_or_error.release_value();
while (!tar_stream->finished()) {
auto const& header = tar_stream->header();
if (!header.content_is_like_extended_header()) {
if (tar_stream->advance().is_error())
return 0;
else
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;
}
if (tar_stream->advance().is_error())
return 0;
}
return 0;
}
|