37 static void error(
const char *err)
39 fprintf(stderr,
"%s", err);
49 c->filesize =
FFMIN(
c->pos,
c->filesize);
52 if (
c->pos > INT64_MAX -
size)
55 memcpy(buf,
c->fuzz,
size);
59 c->filesize =
FFMAX(
c->filesize,
c->pos);
68 if (whence == SEEK_CUR) {
69 if (
offset > INT64_MAX -
c->pos)
72 }
else if (whence == SEEK_END) {
73 if (
offset > INT64_MAX -
c->filesize)
79 if (offset < 0 || offset >
c->filesize)
93 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
100 char filename[1025] = {0};
103 int io_buffer_size = 32768;
110 #ifdef FFMPEG_DEMUXER
111 #define DEMUXER_SYMBOL0(DEMUXER) ff_##DEMUXER##_demuxer
112 #define DEMUXER_SYMBOL(DEMUXER) DEMUXER_SYMBOL0(DEMUXER)
114 fmt = &DEMUXER_SYMBOL(FFMPEG_DEMUXER);
123 error(
"Failed avformat_alloc_context()");
127 io_buffer_size =
size;
128 }
else if (
size > 2048) {
133 memcpy (filename,
data +
size - 1024, 1024);
137 io_buffer_size = bytestream2_get_le32(&gbc) & 0xFFFFFFF;
138 flags = bytestream2_get_byte(&gbc);
139 seekable =
flags & 1;
140 filesize = bytestream2_get_le64(&gbc) & 0x7FFFFFFFFFFFFFFF;
142 if ((
flags & 2) && strlen(filename) <
sizeof(filename) / 2) {
144 void *avif_iter =
NULL;
150 avif_count = bytestream2_get_le32(&gbc) % avif_count;
159 if (strchr(extension,
','))
160 *strchr(extension,
',') = 0;
161 av_strlcatf(filename,
sizeof(filename),
".%s", extension);
166 io_buffer_size =
size;
170 error(
"Failed to allocate pkt");
174 error(
"Failed to allocate io_buffer");
183 error(
"avio_alloc_context failed");
185 avfmt->
pb = fuzzed_pb;
simple assert() macros that are a bit more flexible than ISO C assert().
Libavcodec external API header.
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define flags(name, subs,...)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
const AVInputFormat * av_demuxer_iterate(void **opaque)
Iterate over all registered demuxers.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
#define AVERROR_EOF
End of file.
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
void av_log_set_level(int level)
Set the log level.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
AVIOContext * pb
I/O context.
unsigned char * buffer
Start of the buffer.
This structure stores compressed data.
static int64_t io_seek(void *opaque, int64_t offset, int whence)
static const uint64_t FUZZ_TAG
const uint32_t maxiteration
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
static void error(const char *err)
static int io_read(void *opaque, uint8_t *buf, int buf_size)
static const uint8_t offset[127][2]