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"
23
28
35
37
40 {
43 }
44
45 static void error(
const char *err)
46 {
47 fprintf(stderr, "%s", err);
48 exit(1);
49 }
50
51 static int io_read(
void *opaque, uint8_t *buf,
int buf_size)
52 {
55
57 c->filesize =
FFMIN(
c->pos,
c->filesize);
59 }
60 if (
c->pos > INT64_MAX -
size)
62
63 memcpy(buf,
c->fuzz,
size);
67 c->filesize =
FFMAX(
c->filesize,
c->pos);
68
70 }
71
73 {
75
76 if (whence == SEEK_CUR) {
77 if (
offset > INT64_MAX -
c->pos)
78 return -1;
80 } else if (whence == SEEK_END) {
81 if (
offset > INT64_MAX -
c->filesize)
82 return -1;
86 }
87 if (offset < 0 || offset >
c->filesize)
88 return -1;
89 if (IO_FLAT) {
92 }
94 return 0;
95 }
96
97 // Ensure we don't loop forever
100
105 char filename[1025] = {0};
107 uint8_t *io_buffer;
108 int io_buffer_size = 32768;
112 int seekable = 0;
115 #ifdef FFMPEG_DEMUXER
116 #define DEMUXER_SYMBOL0(DEMUXER) ff_##DEMUXER##_demuxer
117 #define DEMUXER_SYMBOL(DEMUXER) DEMUXER_SYMBOL0(DEMUXER)
119 fmt = &DEMUXER_SYMBOL(FFMPEG_DEMUXER).
p;
120 #endif
121
125 }
126
127 if (!avfmt)
128 error(
"Failed avformat_alloc_context()");
129
130 if (IO_FLAT) {
131 seekable = 1;
132 io_buffer_size =
size;
133 }
else if (
size > 2048) {
135 char extension[64];
136
138 memcpy (filename,
data +
size - 1024, 1024);
141
142 io_buffer_size = bytestream2_get_le32(&gbc) & 0xFFFFFFF;
143 flags = bytestream2_get_byte(&gbc);
144 seekable =
flags & 1;
145 filesize = bytestream2_get_le64(&gbc) & 0x7FFFFFFFFFFFFFFF;
146
147 if ((
flags & 2) && strlen(filename) <
sizeof(filename) / 2) {
149 void *avif_iter =
NULL;
150 int avif_count = 0;
153 avif_count ++;
154 }
155 avif_count = bytestream2_get_le32(&gbc) % avif_count;
156
160 if (!avif_count--)
161 break;
162 }
164 if (strchr(extension, ','))
165 *strchr(extension, ',') = 0;
166 av_strlcatf(filename,
sizeof(filename),
".%s", extension);
167 }
168
171 }
172
173 // HLS uses a loop with sleep, we thus must breakout or we timeout
174 if (fmt && !strcmp(fmt->
name,
"hls"))
176
178 io_buffer_size =
size;
179
182 error(
"Failed to allocate pkt");
183
185 if (!io_buffer)
186 error(
"Failed to allocate io_buffer");
187
194 if (!fuzzed_pb)
195 error(
"avio_alloc_context failed");
196
197 avfmt->
pb = fuzzed_pb;
198
202 }
203
205
206 //TODO, test seeking
207
211 break;
213 }
214
220
221 return 0;
222
223 }