Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2023 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | #include <fftw3.h> |
13 | | #include <string> |
14 | | |
15 | 320 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
16 | | // For reference, fftw_compelx is defined: |
17 | | // typedef double fftw_complex[2] |
18 | 320 | if (size < 1) { |
19 | 0 | return 0; |
20 | 0 | } |
21 | 320 | uint8_t ARRAY_SIZE = (*data) % 250 + 1; |
22 | 320 | data++; |
23 | 320 | size -= 1; |
24 | 320 | if ((ARRAY_SIZE * sizeof(double) * 2) > size) { |
25 | 35 | return 0; |
26 | 35 | } |
27 | 285 | fftw_complex signal[ARRAY_SIZE]; |
28 | 285 | fftw_complex result[ARRAY_SIZE]; |
29 | | |
30 | | // Seed the signals with fuzz data |
31 | 285 | memcpy(signal, data, (ARRAY_SIZE * sizeof(double) * 2)); |
32 | | |
33 | 285 | fftw_plan plan = |
34 | 285 | fftw_plan_dft_1d(ARRAY_SIZE, signal, result, FFTW_FORWARD, FFTW_ESTIMATE); |
35 | | |
36 | 285 | fftw_execute(plan); |
37 | 285 | fftw_destroy_plan(plan); |
38 | | |
39 | 285 | return 0; |
40 | 320 | } |