Coverage Report

Created: 2026-05-30 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/flac/include/share/alloc.h
Line
Count
Source
1
/* alloc - Convenience routines for safely allocating memory
2
 * Copyright (C) 2007-2009  Josh Coalson
3
 * Copyright (C) 2011-2025  Xiph.Org Foundation
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 * notice, this list of conditions and the following disclaimer.
11
 *
12
 * - Redistributions in binary form must reproduce the above copyright
13
 * notice, this list of conditions and the following disclaimer in the
14
 * documentation and/or other materials provided with the distribution.
15
 *
16
 * - Neither the name of the Xiph.org Foundation nor the names of its
17
 * contributors may be used to endorse or promote products derived from
18
 * this software without specific prior written permission.
19
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
 * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
 */
32
33
#ifndef FLAC__SHARE__ALLOC_H
34
#define FLAC__SHARE__ALLOC_H
35
36
#ifdef HAVE_CONFIG_H
37
#  include <config.h>
38
#endif
39
40
/* WATCHOUT: for c++ you may have to #define __STDC_LIMIT_MACROS 1 real early
41
 * before #including this file,  otherwise SIZE_MAX might not be defined
42
 */
43
44
#include <limits.h> /* for SIZE_MAX */
45
#ifdef HAVE_STDINT_H
46
#include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
47
#endif
48
#include <stdlib.h> /* for size_t, malloc(), etc */
49
#include "share/compat.h"
50
51
#ifndef SIZE_MAX
52
# ifndef SIZE_T_MAX
53
#  ifdef _MSC_VER
54
#   ifdef _WIN64
55
#    define SIZE_T_MAX FLAC__U64L(0xffffffffffffffff)
56
#   else
57
#    define SIZE_T_MAX 0xffffffff
58
#   endif
59
#  else
60
#   error
61
#  endif
62
# endif
63
# define SIZE_MAX SIZE_T_MAX
64
#endif
65
66
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
67
68
extern int alloc_check_threshold, alloc_check_counter, alloc_check_keep_failing;
69
70
1.77M
static inline int alloc_check(void) {
71
1.77M
  if(alloc_check_threshold == INT32_MAX)
72
1.49M
    return 0;
73
280k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
383
    return 1;
75
279k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
279k
  else {
78
279k
    return 0;
79
279k
  }
80
1.77M
}
metadata_object.c:alloc_check
Line
Count
Source
70
40.6k
static inline int alloc_check(void) {
71
40.6k
  if(alloc_check_threshold == INT32_MAX)
72
27.7k
    return 0;
73
12.8k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
10
    return 1;
75
12.8k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
12.8k
  else {
78
12.8k
    return 0;
79
12.8k
  }
80
40.6k
}
stream_decoder.c:alloc_check
Line
Count
Source
70
44.8k
static inline int alloc_check(void) {
71
44.8k
  if(alloc_check_threshold == INT32_MAX)
72
32.9k
    return 0;
73
11.8k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
50
    return 1;
75
11.8k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
11.8k
  else {
78
11.8k
    return 0;
79
11.8k
  }
80
44.8k
}
stream_encoder.c:alloc_check
Line
Count
Source
70
84.2k
static inline int alloc_check(void) {
71
84.2k
  if(alloc_check_threshold == INT32_MAX)
72
33.7k
    return 0;
73
50.5k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
19
    return 1;
75
50.5k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
50.5k
  else {
78
50.5k
    return 0;
79
50.5k
  }
80
84.2k
}
Unexecuted instantiation: ogg_decoder_aspect.c:alloc_check
ogg_helper.c:alloc_check
Line
Count
Source
70
4.61k
static inline int alloc_check(void) {
71
4.61k
  if(alloc_check_threshold == INT32_MAX)
72
3.82k
    return 0;
73
790
  else if(alloc_check_counter++ == alloc_check_threshold)
74
35
    return 1;
75
755
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
755
  else {
78
755
    return 0;
79
755
  }
80
4.61k
}
bitwriter.c:alloc_check
Line
Count
Source
70
9.00k
static inline int alloc_check(void) {
71
9.00k
  if(alloc_check_threshold == INT32_MAX)
72
7.44k
    return 0;
73
1.55k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
40
    return 1;
75
1.51k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
1.51k
  else {
78
1.51k
    return 0;
79
1.51k
  }
80
9.00k
}
format.c:alloc_check
Line
Count
Source
70
892k
static inline int alloc_check(void) {
71
892k
  if(alloc_check_threshold == INT32_MAX)
72
782k
    return 0;
73
110k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
77
    return 1;
75
110k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
110k
  else {
78
110k
    return 0;
79
110k
  }
80
892k
}
md5.c:alloc_check
Line
Count
Source
70
12.5k
static inline int alloc_check(void) {
71
12.5k
  if(alloc_check_threshold == INT32_MAX)
72
8.23k
    return 0;
73
4.32k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
97
    return 1;
75
4.22k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
4.22k
  else {
78
4.22k
    return 0;
79
4.22k
  }
80
12.5k
}
memory.c:alloc_check
Line
Count
Source
70
689k
static inline int alloc_check(void) {
71
689k
  if(alloc_check_threshold == INT32_MAX)
72
601k
    return 0;
73
87.6k
  else if(alloc_check_counter++ == alloc_check_threshold)
74
55
    return 1;
75
87.5k
  else if(alloc_check_keep_failing && (alloc_check_counter > alloc_check_threshold))
76
0
    return 1;
77
87.5k
  else {
78
87.5k
    return 0;
79
87.5k
  }
80
689k
}
81
82
#endif
83
84
/* avoid malloc()ing 0 bytes, see:
85
 * https://www.securecoding.cert.org/confluence/display/seccode/MEM04-A.+Do+not+make+assumptions+about+the+result+of+allocating+0+bytes?focusedCommentId=5407003
86
*/
87
88
static inline void *safe_malloc_(size_t size)
89
713k
{
90
713k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
91
  /* Fail if requested */
92
713k
  if(alloc_check())
93
95
    return NULL;
94
713k
#endif
95
  /* malloc(0) is undefined; FLAC src convention is to always allocate */
96
713k
  if(!size)
97
0
    size++;
98
713k
  return malloc(size);
99
713k
}
metadata_object.c:safe_malloc_
Line
Count
Source
89
19.8k
{
90
19.8k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
91
  /* Fail if requested */
92
19.8k
  if(alloc_check())
93
5
    return NULL;
94
19.8k
#endif
95
  /* malloc(0) is undefined; FLAC src convention is to always allocate */
96
19.8k
  if(!size)
97
0
    size++;
98
19.8k
  return malloc(size);
99
19.8k
}
Unexecuted instantiation: stream_decoder.c:safe_malloc_
Unexecuted instantiation: stream_encoder.c:safe_malloc_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_
ogg_helper.c:safe_malloc_
Line
Count
Source
89
4.61k
{
90
4.61k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
91
  /* Fail if requested */
92
4.61k
  if(alloc_check())
93
35
    return NULL;
94
4.58k
#endif
95
  /* malloc(0) is undefined; FLAC src convention is to always allocate */
96
4.58k
  if(!size)
97
0
    size++;
98
4.58k
  return malloc(size);
99
4.61k
}
Unexecuted instantiation: bitwriter.c:safe_malloc_
Unexecuted instantiation: format.c:safe_malloc_
md5.c:safe_malloc_
Line
Count
Source
89
97
{
90
97
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
91
  /* Fail if requested */
92
97
  if(alloc_check())
93
0
    return NULL;
94
97
#endif
95
  /* malloc(0) is undefined; FLAC src convention is to always allocate */
96
97
  if(!size)
97
0
    size++;
98
97
  return malloc(size);
99
97
}
memory.c:safe_malloc_
Line
Count
Source
89
689k
{
90
689k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
91
  /* Fail if requested */
92
689k
  if(alloc_check())
93
55
    return NULL;
94
689k
#endif
95
  /* malloc(0) is undefined; FLAC src convention is to always allocate */
96
689k
  if(!size)
97
0
    size++;
98
689k
  return malloc(size);
99
689k
}
100
101
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
102
static inline void *malloc_(size_t size)
103
15.2k
{
104
  /* Fail if requested */
105
15.2k
  if(alloc_check())
106
40
    return NULL;
107
15.1k
  return malloc(size);
108
15.2k
}
Unexecuted instantiation: metadata_object.c:malloc_
stream_decoder.c:malloc_
Line
Count
Source
103
15.2k
{
104
  /* Fail if requested */
105
15.2k
  if(alloc_check())
106
40
    return NULL;
107
15.1k
  return malloc(size);
108
15.2k
}
Unexecuted instantiation: stream_encoder.c:malloc_
Unexecuted instantiation: ogg_decoder_aspect.c:malloc_
Unexecuted instantiation: ogg_helper.c:malloc_
Unexecuted instantiation: bitwriter.c:malloc_
Unexecuted instantiation: format.c:malloc_
Unexecuted instantiation: md5.c:malloc_
Unexecuted instantiation: memory.c:malloc_
109
#else
110
#define malloc_ malloc
111
#endif
112
113
114
115
static inline void *safe_calloc_(size_t nmemb, size_t size)
116
123k
{
117
123k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
118
  /* Fail if requested */
119
123k
  if(alloc_check())
120
28
    return NULL;
121
123k
#endif
122
123k
  if(!nmemb || !size)
123
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
124
123k
  return calloc(nmemb, size);
125
123k
}
metadata_object.c:safe_calloc_
Line
Count
Source
116
12.7k
{
117
12.7k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
118
  /* Fail if requested */
119
12.7k
  if(alloc_check())
120
3
    return NULL;
121
12.7k
#endif
122
12.7k
  if(!nmemb || !size)
123
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
124
12.7k
  return calloc(nmemb, size);
125
12.7k
}
stream_decoder.c:safe_calloc_
Line
Count
Source
116
26.8k
{
117
26.8k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
118
  /* Fail if requested */
119
26.8k
  if(alloc_check())
120
6
    return NULL;
121
26.8k
#endif
122
26.8k
  if(!nmemb || !size)
123
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
124
26.8k
  return calloc(nmemb, size);
125
26.8k
}
stream_encoder.c:safe_calloc_
Line
Count
Source
116
84.2k
{
117
84.2k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
118
  /* Fail if requested */
119
84.2k
  if(alloc_check())
120
19
    return NULL;
121
84.2k
#endif
122
84.2k
  if(!nmemb || !size)
123
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
124
84.2k
  return calloc(nmemb, size);
125
84.2k
}
Unexecuted instantiation: ogg_decoder_aspect.c:safe_calloc_
Unexecuted instantiation: ogg_helper.c:safe_calloc_
Unexecuted instantiation: bitwriter.c:safe_calloc_
Unexecuted instantiation: format.c:safe_calloc_
Unexecuted instantiation: md5.c:safe_calloc_
Unexecuted instantiation: memory.c:safe_calloc_
126
127
/*@@@@ there's probably a better way to prevent overflows when allocating untrusted sums but this works for now */
128
129
static inline void *safe_malloc_add_2op_(size_t size1, size_t size2)
130
689k
{
131
689k
  size2 += size1;
132
689k
  if(size2 < size1)
133
0
    return 0;
134
689k
  return safe_malloc_(size2);
135
689k
}
Unexecuted instantiation: metadata_object.c:safe_malloc_add_2op_
Unexecuted instantiation: stream_decoder.c:safe_malloc_add_2op_
Unexecuted instantiation: stream_encoder.c:safe_malloc_add_2op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_add_2op_
Unexecuted instantiation: ogg_helper.c:safe_malloc_add_2op_
Unexecuted instantiation: bitwriter.c:safe_malloc_add_2op_
Unexecuted instantiation: format.c:safe_malloc_add_2op_
Unexecuted instantiation: md5.c:safe_malloc_add_2op_
memory.c:safe_malloc_add_2op_
Line
Count
Source
130
689k
{
131
689k
  size2 += size1;
132
689k
  if(size2 < size1)
133
0
    return 0;
134
689k
  return safe_malloc_(size2);
135
689k
}
136
137
static inline void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
138
0
{
139
0
  size2 += size1;
140
0
  if(size2 < size1)
141
0
    return 0;
142
0
  size3 += size2;
143
0
  if(size3 < size2)
144
0
    return 0;
145
0
  return safe_malloc_(size3);
146
0
}
Unexecuted instantiation: metadata_object.c:safe_malloc_add_3op_
Unexecuted instantiation: stream_decoder.c:safe_malloc_add_3op_
Unexecuted instantiation: stream_encoder.c:safe_malloc_add_3op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_add_3op_
Unexecuted instantiation: ogg_helper.c:safe_malloc_add_3op_
Unexecuted instantiation: bitwriter.c:safe_malloc_add_3op_
Unexecuted instantiation: format.c:safe_malloc_add_3op_
Unexecuted instantiation: md5.c:safe_malloc_add_3op_
Unexecuted instantiation: memory.c:safe_malloc_add_3op_
147
148
static inline void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
149
7.94k
{
150
7.94k
  size2 += size1;
151
7.94k
  if(size2 < size1)
152
0
    return 0;
153
7.94k
  size3 += size2;
154
7.94k
  if(size3 < size2)
155
0
    return 0;
156
7.94k
  size4 += size3;
157
7.94k
  if(size4 < size3)
158
0
    return 0;
159
7.94k
  return safe_malloc_(size4);
160
7.94k
}
metadata_object.c:safe_malloc_add_4op_
Line
Count
Source
149
7.94k
{
150
7.94k
  size2 += size1;
151
7.94k
  if(size2 < size1)
152
0
    return 0;
153
7.94k
  size3 += size2;
154
7.94k
  if(size3 < size2)
155
0
    return 0;
156
7.94k
  size4 += size3;
157
7.94k
  if(size4 < size3)
158
0
    return 0;
159
7.94k
  return safe_malloc_(size4);
160
7.94k
}
Unexecuted instantiation: stream_decoder.c:safe_malloc_add_4op_
Unexecuted instantiation: stream_encoder.c:safe_malloc_add_4op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_add_4op_
Unexecuted instantiation: ogg_helper.c:safe_malloc_add_4op_
Unexecuted instantiation: bitwriter.c:safe_malloc_add_4op_
Unexecuted instantiation: format.c:safe_malloc_add_4op_
Unexecuted instantiation: md5.c:safe_malloc_add_4op_
Unexecuted instantiation: memory.c:safe_malloc_add_4op_
161
162
void *safe_malloc_mul_2op_(size_t size1, size_t size2) ;
163
164
static inline void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
165
0
{
166
0
  if(!size1 || !size2 || !size3)
167
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
168
0
  if(size1 > SIZE_MAX / size2)
169
0
    return 0;
170
0
  size1 *= size2;
171
0
  if(size1 > SIZE_MAX / size3)
172
0
    return 0;
173
0
  return malloc_(size1*size3);
174
0
}
Unexecuted instantiation: metadata_object.c:safe_malloc_mul_3op_
Unexecuted instantiation: stream_decoder.c:safe_malloc_mul_3op_
Unexecuted instantiation: stream_encoder.c:safe_malloc_mul_3op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_mul_3op_
Unexecuted instantiation: ogg_helper.c:safe_malloc_mul_3op_
Unexecuted instantiation: bitwriter.c:safe_malloc_mul_3op_
Unexecuted instantiation: format.c:safe_malloc_mul_3op_
Unexecuted instantiation: md5.c:safe_malloc_mul_3op_
Unexecuted instantiation: memory.c:safe_malloc_mul_3op_
175
176
/* size1*size2 + size3 */
177
static inline void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
178
0
{
179
0
  if(!size1 || !size2)
180
0
    return safe_malloc_(size3);
181
0
  if(size1 > SIZE_MAX / size2)
182
0
    return 0;
183
0
  return safe_malloc_add_2op_(size1*size2, size3);
184
0
}
Unexecuted instantiation: metadata_object.c:safe_malloc_mul2add_
Unexecuted instantiation: stream_decoder.c:safe_malloc_mul2add_
Unexecuted instantiation: stream_encoder.c:safe_malloc_mul2add_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_mul2add_
Unexecuted instantiation: ogg_helper.c:safe_malloc_mul2add_
Unexecuted instantiation: bitwriter.c:safe_malloc_mul2add_
Unexecuted instantiation: format.c:safe_malloc_mul2add_
Unexecuted instantiation: md5.c:safe_malloc_mul2add_
Unexecuted instantiation: memory.c:safe_malloc_mul2add_
185
186
/* size1 * (size2 + size3) */
187
static inline void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
188
15.2k
{
189
15.2k
  if(!size1 || (!size2 && !size3))
190
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
191
15.2k
  size2 += size3;
192
15.2k
  if(size2 < size3)
193
0
    return 0;
194
15.2k
  if(size1 > SIZE_MAX / size2)
195
0
    return 0;
196
15.2k
  return malloc_(size1*size2);
197
15.2k
}
Unexecuted instantiation: metadata_object.c:safe_malloc_muladd2_
stream_decoder.c:safe_malloc_muladd2_
Line
Count
Source
188
15.2k
{
189
15.2k
  if(!size1 || (!size2 && !size3))
190
0
    return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
191
15.2k
  size2 += size3;
192
15.2k
  if(size2 < size3)
193
0
    return 0;
194
15.2k
  if(size1 > SIZE_MAX / size2)
195
0
    return 0;
196
15.2k
  return malloc_(size1*size2);
197
15.2k
}
Unexecuted instantiation: stream_encoder.c:safe_malloc_muladd2_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_malloc_muladd2_
Unexecuted instantiation: ogg_helper.c:safe_malloc_muladd2_
Unexecuted instantiation: bitwriter.c:safe_malloc_muladd2_
Unexecuted instantiation: format.c:safe_malloc_muladd2_
Unexecuted instantiation: md5.c:safe_malloc_muladd2_
Unexecuted instantiation: memory.c:safe_malloc_muladd2_
198
199
static inline void *safe_realloc_(void *ptr, size_t size)
200
908k
{
201
908k
  void *oldptr;
202
908k
  void *newptr;
203
908k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
204
  /* Fail if requested */
205
908k
  if(alloc_check() && size > 0) {
206
178
    free(ptr);
207
178
    return NULL;
208
178
  }
209
907k
#endif
210
907k
  oldptr = ptr;
211
907k
  newptr = realloc(ptr, size);
212
907k
  if(size > 0 && newptr == 0)
213
0
    free(oldptr);
214
907k
  return newptr;
215
908k
}
Unexecuted instantiation: metadata_object.c:safe_realloc_
stream_decoder.c:safe_realloc_
Line
Count
Source
200
2.81k
{
201
2.81k
  void *oldptr;
202
2.81k
  void *newptr;
203
2.81k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
204
  /* Fail if requested */
205
2.81k
  if(alloc_check() && size > 0) {
206
4
    free(ptr);
207
4
    return NULL;
208
4
  }
209
2.81k
#endif
210
2.81k
  oldptr = ptr;
211
2.81k
  newptr = realloc(ptr, size);
212
2.81k
  if(size > 0 && newptr == 0)
213
0
    free(oldptr);
214
2.81k
  return newptr;
215
2.81k
}
Unexecuted instantiation: stream_encoder.c:safe_realloc_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_
Unexecuted instantiation: ogg_helper.c:safe_realloc_
Unexecuted instantiation: bitwriter.c:safe_realloc_
format.c:safe_realloc_
Line
Count
Source
200
892k
{
201
892k
  void *oldptr;
202
892k
  void *newptr;
203
892k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
204
  /* Fail if requested */
205
892k
  if(alloc_check() && size > 0) {
206
77
    free(ptr);
207
77
    return NULL;
208
77
  }
209
892k
#endif
210
892k
  oldptr = ptr;
211
892k
  newptr = realloc(ptr, size);
212
892k
  if(size > 0 && newptr == 0)
213
0
    free(oldptr);
214
892k
  return newptr;
215
892k
}
md5.c:safe_realloc_
Line
Count
Source
200
12.4k
{
201
12.4k
  void *oldptr;
202
12.4k
  void *newptr;
203
12.4k
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
204
  /* Fail if requested */
205
12.4k
  if(alloc_check() && size > 0) {
206
97
    free(ptr);
207
97
    return NULL;
208
97
  }
209
12.3k
#endif
210
12.3k
  oldptr = ptr;
211
12.3k
  newptr = realloc(ptr, size);
212
12.3k
  if(size > 0 && newptr == 0)
213
0
    free(oldptr);
214
12.3k
  return newptr;
215
12.4k
}
Unexecuted instantiation: memory.c:safe_realloc_
216
217
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
218
static inline void *realloc_(void *ptr, size_t size)
219
16.9k
{
220
  /* Fail if requested */
221
16.9k
  if(alloc_check())
222
42
    return NULL;
223
16.9k
  return realloc(ptr, size);
224
16.9k
}
metadata_object.c:realloc_
Line
Count
Source
219
7.94k
{
220
  /* Fail if requested */
221
7.94k
  if(alloc_check())
222
2
    return NULL;
223
7.94k
  return realloc(ptr, size);
224
7.94k
}
Unexecuted instantiation: stream_decoder.c:realloc_
Unexecuted instantiation: stream_encoder.c:realloc_
Unexecuted instantiation: ogg_decoder_aspect.c:realloc_
Unexecuted instantiation: ogg_helper.c:realloc_
bitwriter.c:realloc_
Line
Count
Source
219
9.00k
{
220
  /* Fail if requested */
221
9.00k
  if(alloc_check())
222
40
    return NULL;
223
8.96k
  return realloc(ptr, size);
224
9.00k
}
Unexecuted instantiation: format.c:realloc_
Unexecuted instantiation: md5.c:realloc_
Unexecuted instantiation: memory.c:realloc_
225
#else
226
#define realloc_ realloc
227
#endif
228
229
230
static inline void *safe_realloc_nofree_add_2op_(void *ptr, size_t size1, size_t size2)
231
7.94k
{
232
7.94k
  size2 += size1;
233
7.94k
  if(size2 < size1)
234
0
    return 0;
235
7.94k
  return realloc_(ptr, size2);
236
7.94k
}
metadata_object.c:safe_realloc_nofree_add_2op_
Line
Count
Source
231
7.94k
{
232
7.94k
  size2 += size1;
233
7.94k
  if(size2 < size1)
234
0
    return 0;
235
7.94k
  return realloc_(ptr, size2);
236
7.94k
}
Unexecuted instantiation: stream_decoder.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: stream_encoder.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: ogg_helper.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: bitwriter.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: format.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: md5.c:safe_realloc_nofree_add_2op_
Unexecuted instantiation: memory.c:safe_realloc_nofree_add_2op_
237
238
static inline void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
239
0
{
240
0
  size2 += size1;
241
0
  if(size2 < size1) {
242
0
    free(ptr);
243
0
    return 0;
244
0
  }
245
0
  size3 += size2;
246
0
  if(size3 < size2) {
247
0
    free(ptr);
248
0
    return 0;
249
0
  }
250
0
  return safe_realloc_(ptr, size3);
251
0
}
Unexecuted instantiation: metadata_object.c:safe_realloc_add_3op_
Unexecuted instantiation: stream_decoder.c:safe_realloc_add_3op_
Unexecuted instantiation: stream_encoder.c:safe_realloc_add_3op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_add_3op_
Unexecuted instantiation: ogg_helper.c:safe_realloc_add_3op_
Unexecuted instantiation: bitwriter.c:safe_realloc_add_3op_
Unexecuted instantiation: format.c:safe_realloc_add_3op_
Unexecuted instantiation: md5.c:safe_realloc_add_3op_
Unexecuted instantiation: memory.c:safe_realloc_add_3op_
252
253
static inline void *safe_realloc_nofree_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
254
0
{
255
0
  size2 += size1;
256
0
  if(size2 < size1)
257
0
    return 0;
258
0
  size3 += size2;
259
0
  if(size3 < size2)
260
0
    return 0;
261
0
  return realloc_(ptr, size3);
262
0
}
Unexecuted instantiation: metadata_object.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: stream_decoder.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: stream_encoder.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: ogg_helper.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: bitwriter.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: format.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: md5.c:safe_realloc_nofree_add_3op_
Unexecuted instantiation: memory.c:safe_realloc_nofree_add_3op_
263
264
static inline void *safe_realloc_nofree_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
265
0
{
266
0
  size2 += size1;
267
0
  if(size2 < size1)
268
0
    return 0;
269
0
  size3 += size2;
270
0
  if(size3 < size2)
271
0
    return 0;
272
0
  size4 += size3;
273
0
  if(size4 < size3)
274
0
    return 0;
275
0
  return realloc_(ptr, size4);
276
0
}
Unexecuted instantiation: metadata_object.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: stream_decoder.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: stream_encoder.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: ogg_helper.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: bitwriter.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: format.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: md5.c:safe_realloc_nofree_add_4op_
Unexecuted instantiation: memory.c:safe_realloc_nofree_add_4op_
277
278
static inline void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
279
2.81k
{
280
2.81k
  if(!size1 || !size2)
281
0
    return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
282
2.81k
  if(size1 > SIZE_MAX / size2) {
283
0
    free(ptr);
284
0
    return 0;
285
0
  }
286
2.81k
  return safe_realloc_(ptr, size1*size2);
287
2.81k
}
Unexecuted instantiation: metadata_object.c:safe_realloc_mul_2op_
stream_decoder.c:safe_realloc_mul_2op_
Line
Count
Source
279
2.81k
{
280
2.81k
  if(!size1 || !size2)
281
0
    return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
282
2.81k
  if(size1 > SIZE_MAX / size2) {
283
0
    free(ptr);
284
0
    return 0;
285
0
  }
286
2.81k
  return safe_realloc_(ptr, size1*size2);
287
2.81k
}
Unexecuted instantiation: stream_encoder.c:safe_realloc_mul_2op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_mul_2op_
Unexecuted instantiation: ogg_helper.c:safe_realloc_mul_2op_
Unexecuted instantiation: bitwriter.c:safe_realloc_mul_2op_
Unexecuted instantiation: format.c:safe_realloc_mul_2op_
Unexecuted instantiation: md5.c:safe_realloc_mul_2op_
Unexecuted instantiation: memory.c:safe_realloc_mul_2op_
288
289
static inline void *safe_realloc_nofree_mul_2op_(void *ptr, size_t size1, size_t size2)
290
9.00k
{
291
9.00k
  if(!size1 || !size2)
292
0
    return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
293
9.00k
  if(size1 > SIZE_MAX / size2)
294
0
    return 0;
295
9.00k
  return realloc_(ptr, size1*size2);
296
9.00k
}
Unexecuted instantiation: metadata_object.c:safe_realloc_nofree_mul_2op_
Unexecuted instantiation: stream_decoder.c:safe_realloc_nofree_mul_2op_
Unexecuted instantiation: stream_encoder.c:safe_realloc_nofree_mul_2op_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_nofree_mul_2op_
Unexecuted instantiation: ogg_helper.c:safe_realloc_nofree_mul_2op_
bitwriter.c:safe_realloc_nofree_mul_2op_
Line
Count
Source
290
9.00k
{
291
9.00k
  if(!size1 || !size2)
292
0
    return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
293
9.00k
  if(size1 > SIZE_MAX / size2)
294
0
    return 0;
295
9.00k
  return realloc_(ptr, size1*size2);
296
9.00k
}
Unexecuted instantiation: format.c:safe_realloc_nofree_mul_2op_
Unexecuted instantiation: md5.c:safe_realloc_nofree_mul_2op_
Unexecuted instantiation: memory.c:safe_realloc_nofree_mul_2op_
297
298
/* size1 * (size2 + size3) */
299
static inline void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
300
0
{
301
0
  if(!size1 || (!size2 && !size3))
302
0
    return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
303
0
  size2 += size3;
304
0
  if(size2 < size3) {
305
0
    free(ptr);
306
0
    return 0;
307
0
  }
308
0
  return safe_realloc_mul_2op_(ptr, size1, size2);
309
0
}
Unexecuted instantiation: metadata_object.c:safe_realloc_muladd2_
Unexecuted instantiation: stream_decoder.c:safe_realloc_muladd2_
Unexecuted instantiation: stream_encoder.c:safe_realloc_muladd2_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_muladd2_
Unexecuted instantiation: ogg_helper.c:safe_realloc_muladd2_
Unexecuted instantiation: bitwriter.c:safe_realloc_muladd2_
Unexecuted instantiation: format.c:safe_realloc_muladd2_
Unexecuted instantiation: md5.c:safe_realloc_muladd2_
Unexecuted instantiation: memory.c:safe_realloc_muladd2_
310
311
/* size1 * (size2 + size3) */
312
static inline void *safe_realloc_nofree_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
313
0
{
314
0
  if(!size1 || (!size2 && !size3))
315
0
    return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
316
0
  size2 += size3;
317
0
  if(size2 < size3)
318
0
    return 0;
319
0
  return safe_realloc_nofree_mul_2op_(ptr, size1, size2);
320
0
}
Unexecuted instantiation: metadata_object.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: stream_decoder.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: stream_encoder.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: ogg_decoder_aspect.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: ogg_helper.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: bitwriter.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: format.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: md5.c:safe_realloc_nofree_muladd2_
Unexecuted instantiation: memory.c:safe_realloc_nofree_muladd2_
321
322
#endif