1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "config.h"
22
26
27
34
36
39 {
42 }
43
44 static void error(
const char *err)
45 {
46 fprintf(stderr, "%s", err);
47 exit(1);
48 }
49
50 static int io_read(
void *opaque, uint8_t *buf,
int buf_size)
51 {
54
56 c->filesize =
FFMIN(
c->pos,
c->filesize);
58 }
59 if (
c->pos > INT64_MAX -
size)
61
62 memcpy(buf,
c->fuzz,
size);
66 c->filesize =
FFMAX(
c->filesize,
c->pos);
67
69 }
70
72 {
74
75 if (whence == SEEK_CUR) {
76 if (
offset > INT64_MAX -
c->pos)
77 return -1;
79 } else if (whence == SEEK_END) {
80 if (
offset > INT64_MAX -
c->filesize)
81 return -1;
85 }
86 if (offset < 0 || offset >
c->filesize)
87 return -1;
88 if (IO_FLAT) {
91 }
93 return 0;
94 }
95
96 // Ensure we don't loop forever
99
100 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
101
107 char filename[1025] = {0};
109 uint8_t *io_buffer;
110 int io_buffer_size = 32768;
114 int seekable = 0;
117 #ifdef FFMPEG_DEMUXER
118 #define DEMUXER_SYMBOL0(DEMUXER) ff_##DEMUXER##_demuxer
119 #define DEMUXER_SYMBOL(DEMUXER) DEMUXER_SYMBOL0(DEMUXER)
121 fmt = &DEMUXER_SYMBOL(FFMPEG_DEMUXER);
122 #endif
123
127 }
128
129 if (!avfmt)
130 error(
"Failed avformat_alloc_context()");
131
132 if (IO_FLAT) {
133 seekable = 1;
134 io_buffer_size =
size;
135 }
else if (
size > 2048) {
137 char extension[64];
138
140 memcpy (filename,
data +
size - 1024, 1024);
143
144 io_buffer_size = bytestream2_get_le32(&gbc) & 0xFFFFFFF;
145 flags = bytestream2_get_byte(&gbc);
146 seekable =
flags & 1;
147 filesize = bytestream2_get_le64(&gbc) & 0x7FFFFFFFFFFFFFFF;
148
149 if ((
flags & 2) && strlen(filename) <
sizeof(filename) / 2) {
151 void *avif_iter =
NULL;
152 int avif_count = 0;
155 avif_count ++;
156 }
157 avif_count = bytestream2_get_le32(&gbc) % avif_count;
158
162 if (!avif_count--)
163 break;
164 }
166 if (strchr(extension, ','))
167 *strchr(extension, ',') = 0;
168 av_strlcatf(filename,
sizeof(filename),
".%s", extension);
169 }
170
173 }
174
175 // HLS uses a loop with sleep, we thus must breakout or we timeout
176 if (fmt && !strcmp(fmt->
name,
"hls"))
178
180 io_buffer_size =
size;
181
184 error(
"Failed to allocate pkt");
185
187 if (!io_buffer)
188 error(
"Failed to allocate io_buffer");
189
196 if (!fuzzed_pb)
197 error(
"avio_alloc_context failed");
198
199 avfmt->
pb = fuzzed_pb;
200
204 }
205
207
208 //TODO, test seeking
209
213 break;
215 }
216
222
223 return 0;
224
225 }