/src/yara/tests/oss-fuzz/tlsh_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | Copyright (c) 2026. The YARA Authors. All Rights Reserved. |
3 | | |
4 | | Redistribution and use in source and binary forms, with or without modification, |
5 | | are permitted provided that the following conditions are met: |
6 | | |
7 | | 1. Redistributions of source code must retain the above copyright notice, this |
8 | | list of conditions and the following disclaimer. |
9 | | |
10 | | 2. Redistributions in binary form must reproduce the above copyright notice, |
11 | | this list of conditions and the following disclaimer in the documentation and/or |
12 | | other materials provided with the distribution. |
13 | | |
14 | | 3. Neither the name of the copyright holder nor the names of its contributors |
15 | | may be used to endorse or promote products derived from this software without |
16 | | specific prior written permission. |
17 | | |
18 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
19 | | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
20 | | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
21 | | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
22 | | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
23 | | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
24 | | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
25 | | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
27 | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | | */ |
29 | | |
30 | | #include <stddef.h> |
31 | | #include <stdint.h> |
32 | | #include <tlshc/tlsh.h> |
33 | | |
34 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
35 | 479 | { |
36 | 479 | if (size < 50) // TLSH works better with more data |
37 | 11 | return 0; |
38 | | |
39 | 468 | Tlsh* tlsh = tlsh_new(); |
40 | 468 | if (!tlsh) |
41 | 0 | return 0; |
42 | | |
43 | | // Split data into two parts to exercise update |
44 | 468 | size_t first_part = size / 2; |
45 | 468 | tlsh_update(tlsh, data, first_part); |
46 | 468 | tlsh_final(tlsh, data + first_part, size - first_part, 0); |
47 | | |
48 | 468 | tlsh_get_hash(tlsh, true); |
49 | 468 | tlsh_get_hash(tlsh, false); |
50 | | |
51 | 468 | tlsh_reset(tlsh); |
52 | 468 | tlsh_free(tlsh); |
53 | | |
54 | 468 | return 0; |
55 | 468 | } |