/src/libfmapi/ossfuzz/checksum_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * OSS-Fuzz target for libfmapi checksum functions |
3 | | * |
4 | | * Copyright (C) 2011-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 "../libfmapi/libfmapi_checksum.h" |
30 | | |
31 | | int LLVMFuzzerTestOneInput( |
32 | | const uint8_t *data, |
33 | | size_t size ) |
34 | 49 | { |
35 | 49 | uint32_t checksum = 0; |
36 | | |
37 | 49 | uint32_t initial_value = 0; |
38 | | |
39 | 49 | if( size >= 3 ) |
40 | 46 | { |
41 | 46 | initial_value = (uint32_t) data[ 0 ] |
42 | 46 | | ( (uint32_t) data[ 1 ] << 8 ) |
43 | 46 | | ( (uint32_t) data[ 2 ] << 16 ); |
44 | 46 | } |
45 | 49 | if( libfmapi_checksum_calculate_crc32( |
46 | 49 | &checksum, |
47 | 49 | data, |
48 | 49 | size, |
49 | 49 | 0, |
50 | 49 | NULL ) != 1 ) |
51 | 0 | { |
52 | 0 | return( 0 ); |
53 | 0 | } |
54 | 49 | libfmapi_checksum_calculate_weak_crc32( |
55 | 49 | &checksum, |
56 | 49 | data, |
57 | 49 | size, |
58 | 49 | 0, |
59 | 49 | NULL ); |
60 | | |
61 | 49 | libfmapi_checksum_calculate_weak_crc32( |
62 | 49 | &checksum, |
63 | 49 | data, |
64 | 49 | size, |
65 | 49 | initial_value, |
66 | 49 | NULL ); |
67 | | |
68 | 49 | return( 0 ); |
69 | 49 | } |
70 | | |
71 | | } /* extern "C" */ |