/src/libarchive_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2016 Google Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | // |
15 | | //////////////////////////////////////////////////////////////////////////////// |
16 | | #include <stddef.h> |
17 | | #include <stdint.h> |
18 | | #include <vector> |
19 | | |
20 | | #include "archive.h" |
21 | | #include "archive_entry.h" |
22 | | |
23 | 10.9k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { |
24 | 10.9k | struct archive *a = archive_read_new(); |
25 | | |
26 | 10.9k | archive_read_support_filter_all(a); |
27 | 10.9k | archive_read_support_format_all(a); |
28 | 10.9k | archive_read_support_format_empty(a); |
29 | 10.9k | archive_read_support_format_raw(a); |
30 | 10.9k | archive_read_support_format_gnutar(a); |
31 | | |
32 | 10.9k | if (ARCHIVE_OK != archive_read_set_options(a, "zip:ignorecrc32,tar:read_concatenated_archives,tar:mac-ext")) { |
33 | 0 | return 0; |
34 | 0 | } |
35 | | |
36 | 10.9k | archive_read_add_passphrase(a, "secret"); |
37 | | |
38 | 10.9k | if (ARCHIVE_OK != archive_read_open_memory(a, buf, len)) { |
39 | 219 | archive_read_free(a); |
40 | 219 | return 0; |
41 | 219 | } |
42 | | |
43 | 683k | while(1) { |
44 | 683k | std::vector<uint8_t> data_buffer(getpagesize(), 0); |
45 | 683k | struct archive_entry *entry; |
46 | 683k | int ret = archive_read_next_header(a, &entry); |
47 | 683k | if (ret == ARCHIVE_EOF || ret == ARCHIVE_FATAL) |
48 | 8.21k | break; |
49 | 675k | if (ret == ARCHIVE_RETRY) |
50 | 476k | continue; |
51 | | |
52 | 199k | (void)archive_entry_pathname(entry); |
53 | 199k | (void)archive_entry_pathname_utf8(entry); |
54 | 199k | (void)archive_entry_pathname_w(entry); |
55 | | |
56 | 199k | (void)archive_entry_atime(entry); |
57 | 199k | (void)archive_entry_birthtime(entry); |
58 | 199k | (void)archive_entry_ctime(entry); |
59 | 199k | (void)archive_entry_dev(entry); |
60 | 199k | (void)archive_entry_digest(entry, ARCHIVE_ENTRY_DIGEST_SHA1); |
61 | 199k | (void)archive_entry_filetype(entry); |
62 | 199k | (void)archive_entry_gid(entry); |
63 | 199k | (void)archive_entry_is_data_encrypted(entry); |
64 | 199k | (void)archive_entry_is_encrypted(entry); |
65 | 199k | (void)archive_entry_is_metadata_encrypted(entry); |
66 | 199k | (void)archive_entry_mode(entry); |
67 | 199k | (void)archive_entry_mtime(entry); |
68 | 199k | (void)archive_entry_size(entry); |
69 | 199k | (void)archive_entry_uid(entry); |
70 | | |
71 | 199k | ssize_t r; |
72 | 1.68G | while ((r = archive_read_data(a, data_buffer.data(), |
73 | 1.68G | data_buffer.size())) > 0) |
74 | 1.68G | ; |
75 | 199k | if (r == ARCHIVE_FATAL) |
76 | 2.50k | break; |
77 | 199k | } |
78 | | |
79 | 10.7k | archive_read_has_encrypted_entries(a); |
80 | 10.7k | archive_read_format_capabilities(a); |
81 | 10.7k | archive_file_count(a); |
82 | 10.7k | archive_seek_data(a, 0, SEEK_SET); |
83 | | |
84 | 10.7k | archive_read_free(a); |
85 | 10.7k | return 0; |
86 | 10.9k | } |