Raw
1 #include "git-compat-util.h"
2 #include "reftable/basics.h"
3 #include "reftable/blocksource.h"
4 #include "reftable/reftable-blocksource.h"
5 #include "reftable/reftable-error.h"
6 #include "reftable/reftable-iterator.h"
7 #include "reftable/reftable-record.h"
8 #include "reftable/reftable-table.h"
9 #include "reftable/reftable-writer.h"
10
11 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
12
13 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
14 {
15 struct reftable_block_source source = { 0 };
16 struct reftable_buf buf = REFTABLE_BUF_INIT;
17 struct reftable_table *table = NULL;
18 int err;
19
20 if (reftable_buf_add(&buf, (const char *)data, size) < 0)
21 goto out;
22 block_source_from_buf(&source, &buf);
23
24 err = reftable_table_new(&table, &source, "fuzz-input");
25 if (err < 0)
26 goto out;
27
28 /*
29 * Exercise the ref, log and raw block iterators so that we cover as
30 * much of the parsing code as possible.
31 */
32 {
33 struct reftable_ref_record ref = { 0 };
34 struct reftable_iterator it = { 0 };
35
36 reftable_table_init_ref_iterator(table, &it);
37 if (!reftable_iterator_seek_ref(&it, ""))
38 while (!reftable_iterator_next_ref(&it, &ref))
39 ;
40
41 reftable_ref_record_release(&ref);
42 reftable_iterator_destroy(&it);
43 }
44
45 {
46 struct reftable_log_record log = { 0 };
47 struct reftable_iterator it = { 0 };
48
49 reftable_table_init_log_iterator(table, &it);
50 if (!reftable_iterator_seek_log(&it, ""))
51 while (!reftable_iterator_next_log(&it, &log))
52 ;
53
54 reftable_log_record_release(&log);
55 reftable_iterator_destroy(&it);
56 }
57
58 {
59 struct reftable_table_iterator it = { 0 };
60 const struct reftable_block *block;
61
62 if (!reftable_table_iterator_init(&it, table))
63 while (!reftable_table_iterator_next(&it, &block))
64 ;
65
66 reftable_table_iterator_release(&it);
67 }
68
69 out:
70 if (table)
71 reftable_table_decref(table);
72 reftable_buf_release(&buf);
73 return 0;
74 }