/src/jpegoptim/fuzz/fuzz_compression.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include <stdint.h> |
2 | | #include "fuzz_manager.h" |
3 | | #include "jpegoptim.h" |
4 | | |
5 | | int LLVMFuzzerTestOneInput(const uint8_t *data, const size_t size) |
6 | 119 | { |
7 | 119 | int rc = -1; |
8 | 119 | struct stat file_stat; |
9 | | |
10 | 119 | fuzz_manager_init(); |
11 | | |
12 | 119 | if (0 != lstat(fuzz_manager.fuzz_file_name, &file_stat)) { |
13 | | // Getting file stat failed |
14 | 0 | goto end; |
15 | 0 | } |
16 | | |
17 | | // Write data to fuzz file |
18 | 119 | FILE *fuzz_file = fopen(fuzz_manager.fuzz_file_name, "wb+"); |
19 | | |
20 | 119 | if (!fuzz_file) { |
21 | 0 | goto end; |
22 | 0 | } |
23 | | |
24 | 119 | if (size != fwrite(data, sizeof(uint8_t), size, fuzz_file)) { |
25 | 0 | goto end; |
26 | 0 | } |
27 | 119 | fclose(fuzz_file); |
28 | | |
29 | 119 | optimize( |
30 | 119 | fuzz_manager.log_fh, |
31 | 119 | fuzz_manager.fuzz_file_name, |
32 | 119 | fuzz_manager.new_fuzz_file_name, |
33 | 119 | fuzz_manager.tmp_dir, |
34 | 119 | &file_stat, |
35 | 119 | &fuzz_manager.rate, |
36 | 119 | &fuzz_manager.saved |
37 | 119 | ); |
38 | | |
39 | 119 | rc = 0; |
40 | | |
41 | 119 | end: |
42 | 119 | return rc; |
43 | 119 | } |