Coverage Report

Created: 2025-06-22 06:45

/src/fftw3_fuzzer.cc
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
323
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
323
  if (size < 1) {
19
0
    return 0;
20
0
  }
21
323
  uint8_t ARRAY_SIZE = (*data) % 250 + 1;
22
323
  data++;
23
323
  size -= 1;
24
323
  if ((ARRAY_SIZE * sizeof(double) * 2) > size) {
25
35
    return 0;
26
35
  }
27
288
  fftw_complex signal[ARRAY_SIZE];
28
288
  fftw_complex result[ARRAY_SIZE];
29
30
  // Seed the signals with fuzz data
31
288
  memcpy(signal, data, (ARRAY_SIZE * sizeof(double) * 2));
32
33
288
  fftw_plan plan =
34
288
      fftw_plan_dft_1d(ARRAY_SIZE, signal, result, FFTW_FORWARD, FFTW_ESTIMATE);
35
36
288
  fftw_execute(plan);
37
288
  fftw_destroy_plan(plan);
38
39
288
  return 0;
40
323
}