/src/libjpeg-turbo.main/fuzz/cjpeg.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C)2021, 2024, 2026 D. R. Commander. All Rights Reserved. |
3 | | * |
4 | | * Redistribution and use in source and binary forms, with or without |
5 | | * modification, are permitted provided that the following conditions are met: |
6 | | * |
7 | | * - Redistributions of source code must retain the above copyright notice, |
8 | | * this list of conditions and the following disclaimer. |
9 | | * - Redistributions in binary form must reproduce the above copyright notice, |
10 | | * this list of conditions and the following disclaimer in the documentation |
11 | | * and/or other materials provided with the distribution. |
12 | | * - Neither the name of the libjpeg-turbo Project nor the names of its |
13 | | * contributors may be used to endorse or promote products derived from this |
14 | | * software without specific prior written permission. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS", |
17 | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
20 | | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | | * POSSIBILITY OF SUCH DAMAGE. |
27 | | */ |
28 | | |
29 | | /* This fuzz target wraps cjpeg in order to test esoteric compression options |
30 | | as well as the GIF and Targa readers. */ |
31 | | |
32 | | #define CJPEG_FUZZER |
33 | | extern "C" { |
34 | | #include "../src/cjpeg.c" |
35 | | } |
36 | | |
37 | | #include <stdint.h> |
38 | | #include <unistd.h> |
39 | | |
40 | | |
41 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
42 | 10 | { |
43 | 10 | char *argv1[] = { |
44 | 10 | (char *)"cjpeg", (char *)"-dct", (char *)"float", (char *)"-memdst", |
45 | 10 | (char *)"-quality", (char *)"100,99,98", |
46 | 10 | (char *)"-sample", (char *)"4x1,2x2,1x2", (char *)"-targa" |
47 | 10 | }; |
48 | 10 | char *argv2[] = { |
49 | 10 | (char *)"cjpeg", (char *)"-dct", (char *)"float", (char *)"-memdst", |
50 | 10 | (char *)"-quality", (char *)"90,80,70", (char *)"-smooth", (char *)"50", |
51 | 10 | (char *)"-targa" |
52 | 10 | }; |
53 | 10 | FILE *file = NULL; |
54 | | |
55 | 10 | if ((file = fmemopen((void *)data, size, "r")) == NULL) |
56 | 0 | goto bailout; |
57 | | |
58 | 10 | fseek(file, 0, SEEK_SET); |
59 | 10 | cjpeg_fuzzer(9, argv1, file); |
60 | 10 | fseek(file, 0, SEEK_SET); |
61 | 10 | cjpeg_fuzzer(9, argv2, file); |
62 | | |
63 | 10 | argv1[8] = argv2[8] = NULL; |
64 | | |
65 | 10 | fseek(file, 0, SEEK_SET); |
66 | 10 | cjpeg_fuzzer(8, argv1, file); |
67 | 10 | fseek(file, 0, SEEK_SET); |
68 | 10 | cjpeg_fuzzer(8, argv2, file); |
69 | | |
70 | 10 | bailout: |
71 | 10 | if (file) fclose(file); |
72 | 10 | return 0; |
73 | 10 | } |