Coverage Report

Created: 2026-12-01 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/fuzz/fuzz_decode.c
Line
Count
Source
1
/*
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4
**
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
**
19
** Any non-GPL usage of this software or parts of this software is strictly
20
** forbidden.
21
**
22
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24
**
25
** Commercial non-GPL licensing of this software is possible.
26
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27
**/
28
29
#include <stddef.h>
30
#include <stdint.h>
31
#include <string.h>
32
#include <stdlib.h>
33
34
#include "neaacdec.h"
35
36
37
5.69k
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
38
5.69k
  size_t preamble = 2 + 2 + 1 + sizeof(NeAACDecConfiguration);
39
5.69k
  NeAACDecConfiguration config;
40
5.69k
  unsigned long sample_rate;
41
5.69k
  unsigned char num_channels;
42
5.69k
  NeAACDecConfigurationPtr config_ptr;
43
44
5.69k
  if (size < preamble) return 0;
45
5.68k
  size_t len1 = data[0] | (data[1] << 8);
46
5.68k
  data += 2;
47
5.68k
  size_t len2 = data[0] | (data[1] << 8);
48
5.68k
  data += 2;
49
5.68k
  uint8_t flags = data[0];
50
5.68k
  data += 1;
51
5.68k
  memcpy(&config, data, sizeof(NeAACDecConfiguration));
52
5.68k
  data += sizeof(NeAACDecConfiguration);
53
5.68k
  size -= preamble;
54
55
5.68k
  if (len1 + len2 > size) return 0;
56
5.65k
  size_t len3 = size - len1 - len2;
57
5.65k
  int use_init2 = flags & 1;
58
5.65k
  int seek_before = flags & 2;
59
5.65k
  int seek_between = flags & 4;
60
5.65k
  size_t buffer_op = (flags >> 3) & 3;
61
5.65k
  int use_drm = flags & 32;
62
5.65k
  int drm_channels = (flags >> 5) & 7;
63
5.65k
  unsigned long drm_sample_rate = config.defSampleRate;
64
5.65k
  int res, ok;
65
5.65k
  const size_t kBufferSize[4] = {0, 0, 16, 16384};
66
5.65k
  size_t buffer_size = kBufferSize[buffer_op];
67
5.65k
  void* buffer = buffer_size > 0 ? (unsigned char *)malloc(buffer_size) : NULL;
68
69
5.65k
  unsigned char* part1 = (unsigned char *)malloc(len1);
70
5.65k
  unsigned char* part2 = (unsigned char *)malloc(len2);
71
5.65k
  unsigned char* part3 = (unsigned char *)malloc(len3);
72
5.65k
  memcpy(part1, data, len1);
73
5.65k
  data += len1;
74
5.65k
  memcpy(part2, data, len2);
75
5.65k
  data += len2;
76
5.65k
  memcpy(part3, data, len3);
77
5.65k
  data += len3;
78
79
5.65k
  NeAACDecHandle decoder = NeAACDecOpen();
80
5.65k
  ok = NeAACDecSetConfiguration(decoder, &config);
81
5.65k
  if (!ok) goto cleanup;
82
5.57k
  config_ptr = NeAACDecGetCurrentConfiguration(decoder);
83
5.57k
  if (!config_ptr) abort();
84
5.57k
  if (use_init2) {
85
5.12k
    res = NeAACDecInit2(decoder, part1, len1, &sample_rate, &num_channels);
86
5.12k
  } else {
87
454
    res = NeAACDecInit(decoder, part1, len1, &sample_rate, &num_channels);
88
454
  }
89
5.57k
  if (use_drm) {
90
1.32k
    NeAACDecInitDRM(&decoder, drm_sample_rate, drm_channels);
91
1.32k
  }
92
93
5.57k
  if (res != 0) goto cleanup;
94
5.09k
  NeAACDecFrameInfo faad_info;
95
5.09k
  if (seek_before) {
96
1.42k
    NeAACDecPostSeekReset(decoder, 0x1234567);
97
1.42k
  }
98
5.09k
  NeAACDecDecode(decoder, &faad_info, part2, len2);
99
5.09k
  if (seek_between) {
100
2.08k
    NeAACDecPostSeekReset(decoder, -0x1234567);
101
2.08k
  }
102
5.09k
  if (buffer_op == 0) {
103
3.98k
    NeAACDecDecode(decoder, &faad_info, part3, len3);
104
3.98k
  } else {
105
1.11k
    NeAACDecDecode2(decoder, &faad_info, part3, len3, &buffer, buffer_size);
106
1.11k
  }
107
108
5.65k
cleanup:
109
5.65k
  NeAACDecClose(decoder);
110
5.65k
  free(part1);
111
5.65k
  free(part2);
112
5.65k
  free(part3);
113
5.65k
  if (buffer) free(buffer);
114
115
5.65k
  return 0;
116
5.09k
}