Coverage Report

Created: 2023-09-24 16:10

/src/decode_fuzzer.cc
Line
Count
Source
1
#include <stdio.h>
2
#include <string.h>
3
#include <cstdint>
4
#include <vorbis/vorbisfile.h>
5
6
struct vorbis_data {
7
  const uint8_t *current;
8
  const uint8_t *data;
9
  size_t size;
10
};
11
12
1.09M
size_t read_func(void *ptr, size_t size1, size_t size2, void *datasource) {
13
1.09M
  vorbis_data* vd = (vorbis_data *)(datasource);
14
1.09M
  size_t len = size1 * size2;
15
1.09M
  if (vd->current + len > vd->data + vd->size) {
16
80.3k
      len = vd->data + vd->size - vd->current;
17
80.3k
  }
18
1.09M
  memcpy(ptr, vd->current, len);
19
1.09M
  vd->current += len;
20
1.09M
  return len;
21
1.09M
}
22
23
24
50.5k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
50.5k
  ov_callbacks memory_callbacks = {0};
26
50.5k
  memory_callbacks.read_func = read_func;
27
50.5k
  vorbis_data data_st;
28
50.5k
  data_st.size = Size;
29
50.5k
  data_st.current = Data;
30
50.5k
  data_st.data = Data;
31
50.5k
  OggVorbis_File vf;
32
50.5k
  int result = ov_open_callbacks(&data_st, &vf, NULL, 0, memory_callbacks);
33
50.5k
  if (result < 0) {
34
17.4k
    return 0;
35
17.4k
  }
36
33.1k
  int current_section = 0;
37
33.1k
  int eof = 0;
38
33.1k
  char buf[4096];
39
33.1k
  int read_result;
40
104M
  while (!eof) {
41
104M
    read_result = ov_read(&vf, buf, sizeof(buf), 0, 2, 1, &current_section);
42
104M
    if (read_result != OV_HOLE && read_result <= 0) {
43
33.1k
      eof = 1;
44
33.1k
    }
45
104M
  }
46
33.1k
  ov_clear(&vf);
47
33.1k
  return 0;
48
50.5k
}