1 /*
2 * Copyright (c) 2024 Michael Niedermayer <michael-ffmpeg@niedermayer.cc>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Based on target_dec_fuzzer
21 */
22
23 #include "config.h"
30
35
37
39
40 static void error(
const char *err)
41 {
42 fprintf(stderr, "%s", err);
43 exit(1);
44 }
45
47
48 // Ensure we don't loop forever
50
51
53 {
55
59
63 return 0;
66 }
67
69 }
71 }
72
74 uint64_t maxpixels_per_frame = 512 * 512;
75 uint64_t maxpixels;
76
79 uint64_t nb_samples = 0;
81 uint64_t ec_pixels = 0;
82
84 #define ENCODER_SYMBOL0(CODEC) ff_##CODEC##_encoder
85 #define ENCODER_SYMBOL(CODEC) ENCODER_SYMBOL0(CODEC)
88
91 }
92
94 return 0;
95
100 }
101
102 maxpixels_per_frame =
FFMIN(maxpixels_per_frame , maxpixels);
103
106 error(
"Failed memory allocation");
107
108 if (
ctx->max_pixels == 0 ||
ctx->max_pixels > maxpixels_per_frame)
109 ctx->max_pixels = maxpixels_per_frame;
//To reduce false positive OOM and hangs
110
116
119 ctx->width = bytestream2_get_le32(&gbc) & 0xFFFF;
120 ctx->height = bytestream2_get_le32(&gbc) & 0xFFFF;
122 ctx->gop_size = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
123 ctx->max_b_frames = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
124 ctx->time_base.num = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
125 ctx->time_base.den = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
126 ctx->framerate.num = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
127 ctx->framerate.den = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
128
129 flags = bytestream2_get_byte(&gbc);
132
135
136 flags64 = bytestream2_get_le64(&gbc);
137
139 int npixfmts = 0;
141 ;
142 ctx->pix_fmt =
c->
p.
pix_fmts[bytestream2_get_byte(&gbc) % npixfmts];
143 }
144
147 int coder = bytestream2_get_byte(&gbc)&3;
148 if (coder == 3) coder = -2;
152 break;}
153 }
154 }
156 ctx->width =
ctx->height = 64;
157
159 if (res < 0) {
162 return 0; // Failure of avcodec_open2() does not imply that a issue was found
163 }
164
165
168 if (!
frame || !avpkt)
169 error(
"Failed memory allocation");
170
174
176 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
177 if (ec_pixels > maxpixels)
178 goto maximums_reached;
179
181 if (res < 0)
182 error(
"Failed av_frame_get_buffer");
183
188 memset(
frame->buf[
i]->data + buf_size, 0,
frame->buf[
i]->size - buf_size);
190 }
191 }
192
193 frame->pts = nb_samples;
194
196 if (res < 0)
197 break;
201
203 }
204 maximums_reached:
207
208 // fprintf(stderr, "frames encoded: %"PRId64", iterations: %d\n", nb_samples , it);
209
214 return 0;
215 }