/src/libwtcdb/ossfuzz/file_header_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * OSS-Fuzz target for libwtcdb file_header type |
3 | | * |
4 | | * Copyright (C) 2010-2026, Joachim Metz <joachim.metz@gmail.com> |
5 | | * |
6 | | * Refer to AUTHORS for acknowledgements. |
7 | | * |
8 | | * This program is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * This program is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | | */ |
21 | | |
22 | | #include <stddef.h> |
23 | | #include <stdint.h> |
24 | | |
25 | | /* Note that some of the OSS-Fuzz engines use C++ |
26 | | */ |
27 | | extern "C" { |
28 | | |
29 | | #include "ossfuzz_libbfio.h" |
30 | | #include "ossfuzz_libwtcdb.h" |
31 | | |
32 | | #include "../libwtcdb/libwtcdb_file_header.h" |
33 | | |
34 | | int LLVMFuzzerTestOneInput( |
35 | | const uint8_t *data, |
36 | | size_t size ) |
37 | 2.38k | { |
38 | 2.38k | libbfio_handle_t *file_io_handle = NULL; |
39 | 2.38k | libwtcdb_file_header_t *file_header = NULL; |
40 | | |
41 | 2.38k | if( libbfio_memory_range_initialize( |
42 | 2.38k | &file_io_handle, |
43 | 2.38k | NULL ) != 1 ) |
44 | 0 | { |
45 | 0 | return( 0 ); |
46 | 0 | } |
47 | 2.38k | if( libbfio_memory_range_set( |
48 | 2.38k | file_io_handle, |
49 | 2.38k | (uint8_t *) data, |
50 | 2.38k | size, |
51 | 2.38k | NULL ) != 1 ) |
52 | 0 | { |
53 | 0 | goto on_error_libbfio; |
54 | 0 | } |
55 | 2.38k | if( libbfio_handle_open( |
56 | 2.38k | file_io_handle, |
57 | 2.38k | LIBBFIO_OPEN_READ, |
58 | 2.38k | NULL ) != 1 ) |
59 | 0 | { |
60 | 0 | goto on_error_libbfio; |
61 | 0 | } |
62 | 2.38k | if( libwtcdb_file_header_initialize( |
63 | 2.38k | &file_header, |
64 | 2.38k | NULL ) != 1 ) |
65 | 1.67k | { |
66 | 1.67k | goto on_error_libbfio; |
67 | 1.67k | } |
68 | 714 | libwtcdb_file_header_read_data( |
69 | 714 | file_header, |
70 | 714 | data, |
71 | 714 | size, |
72 | 714 | NULL ); |
73 | | /* Attempt to read the file header using the file IO handle |
74 | | * to trigger the validation |
75 | | */ |
76 | 714 | libwtcdb_file_header_read_file_io_handle( |
77 | 714 | file_header, |
78 | 714 | file_io_handle, |
79 | 714 | NULL ); |
80 | | |
81 | 2.38k | on_error_libwtcdb_file_header: |
82 | 2.38k | libwtcdb_file_header_free( |
83 | 2.38k | &file_header, |
84 | 2.38k | NULL ); |
85 | | |
86 | 2.38k | on_error_libbfio: |
87 | 2.38k | libbfio_handle_free( |
88 | 2.38k | &file_io_handle, |
89 | 2.38k | NULL ); |
90 | | |
91 | 2.38k | return( 0 ); |
92 | 2.38k | } |
93 | | |
94 | | } /* extern "C" */ |