63static void error(
const char *err)
65 fprintf(stderr,
"%s", err);
78 error(
"Failed to find decoder");
84 int *got_sub_ptr,
const AVPacket *avpkt)
89 if (ret >= 0 && *got_sub_ptr)
99 *got_frame = ret >= 0;
106static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
113 ptrdiff_t linesize1[4];
128 for (
i = 0;
i < 4 &&
frame->linesize[
i];
i++)
129 linesize1[
i] =
frame->linesize[
i] =
139 for (
i = 0;
i < 4 &&
size[
i];
i++) {
140 switch(
ctx->codec_id) {
165 switch (
ctx->codec_type) {
178 uint64_t maxpixels_per_frame = 4096 * 4096;
181 uint64_t maxsamples_per_frame = 256*1024*32;
184 const uint8_t *last =
data;
187 uint64_t ec_pixels = 0;
188 uint64_t nb_samples = 0;
190 int *got_picture_ptr,
193 uint64_t keyframes = 0;
194 uint64_t flushpattern = -1;
199#define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
200#define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC)
201 extern FFCodec DECODER_SYMBOL(FFMPEG_DECODER);
202 codec_list[0] = &DECODER_SYMBOL(FFMPEG_DECODER);
204 c = &DECODER_SYMBOL(FFMPEG_DECODER);
364 maxsamples_per_frame =
FFMIN(maxsamples_per_frame, maxsamples);
365 maxpixels_per_frame =
FFMIN(maxpixels_per_frame , maxpixels);
372 if (!
ctx || !parser_avctx)
373 error(
"Failed memory allocation");
375 if (
ctx->max_pixels == 0 ||
ctx->max_pixels > maxpixels_per_frame)
376 ctx->max_pixels = maxpixels_per_frame;
378 ctx->max_samples = maxsamples_per_frame;
387 uint64_t request_channel_layout;
392 ctx->width = bytestream2_get_le32(&gbc);
393 ctx->height = bytestream2_get_le32(&gbc);
394 ctx->bit_rate = bytestream2_get_le64(&gbc);
395 ctx->bits_per_coded_sample = bytestream2_get_le32(&gbc);
397 flags = bytestream2_get_byte(&gbc);
415 extradata_size = bytestream2_get_le32(&gbc);
417 ctx->sample_rate = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
419 ctx->block_align = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
420 ctx->codec_tag = bytestream2_get_le32(&gbc);
424 ctx->codec_tag =
c->codec_tags[
ctx->codec_tag % n];
426 keyframes = bytestream2_get_le64(&gbc);
427 request_channel_layout = bytestream2_get_le64(&gbc);
429 ctx->idct_algo = bytestream2_get_byte(&gbc) % 25;
430 flushpattern = bytestream2_get_le64(&gbc);
435 switch (
ctx->codec_id) {
448 if (request_channel_layout) {
449 switch (
ctx->codec_id) {
455 if (request_channel_layout & ~INT64_MIN) {
458 error(
"Failed memory allocation");
459 av_strlcatf(downmix_layout, 19,
"0x%"PRIx64, request_channel_layout & ~INT64_MIN);
471 flags64 = bytestream2_get_le64(&gbc);
483 ctx->workaround_bugs = bytestream2_get_le32(&gbc);
485 if (
c->p.max_lowres) {
486 ctx->lowres = bytestream2_get_byte(&gbc) % (
c->p.max_lowres+1);
489 if (extradata_size <
size) {
491 if (
ctx->extradata) {
492 ctx->extradata_size = extradata_size;
498 ctx->width =
ctx->height = 0;
519 if (!
frame || !avpkt || !parsepkt)
520 error(
"Failed memory allocation");
525 while (
data +
sizeof(fuzz_tag) < end) {
530 if (
data +
sizeof(fuzz_tag) > end)
535 error(
"Failed memory allocation");
536 memcpy(parsepkt->
data, last,
data - last);
538 keyframes = (keyframes >> 2) + (keyframes<<62);
539 data +=
sizeof(fuzz_tag);
542 while (parsepkt->
size > 0) {
548 parsepkt->
pts, parsepkt->
dts, parsepkt->
pos);
549 if (avpkt->
data == parsepkt->
data) {
552 error(
"Failed memory allocation");
555 error(
"Failed memory allocation");
557 parsepkt->
data += ret;
558 parsepkt->
size -= ret;
559 parsepkt->
pos += ret;
571 if (!(flushpattern & 7))
573 flushpattern = (flushpattern >> 3) + (flushpattern << 61);
578 decode_more = ret >= 0;
580 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
581 if (it > 20 || ec_pixels > 4 *
ctx->max_pixels) {
582 ctx->error_concealment = 0;
585 if (ec_pixels > maxpixels)
586 goto maximums_reached;
594 int ret = decode_handler(
ctx,
frame, &got_frame, avpkt);
596 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
597 if (it > 20 || ec_pixels > 4 *
ctx->max_pixels) {
598 ctx->error_concealment = 0;
601 if (ec_pixels > maxpixels)
602 goto maximums_reached;
605 frame->nb_samples == 0 && !got_frame &&
607 nb_samples +=
ctx->max_samples;
609 nb_samples +=
frame->nb_samples;
610 if (nb_samples > maxsamples)
611 goto maximums_reached;
613 if (ret <= 0 || ret > avpkt->
size)
619 decode_more = avpkt->
size > 0;
621 decode_more = ret >= 0;
639 decode_handler(
ctx,
frame, &got_frame, avpkt);
641 nb_samples +=
frame->nb_samples;
642 if (nb_samples > maxsamples)
static AVFormatContext * ctx
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
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,...)
#define i(width, name, range_min, range_max)
#define FF_CODEC_TAGS_END
FFCodec.codec_tags termination value.
static av_always_inline const FFCodec * ffcodec(const AVCodec *codec)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
#define AV_NUM_DATA_POINTERS
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
Decoding only.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
@ AV_CODEC_ID_INTERPLAY_ACM
@ AV_CODEC_ID_BETHSOFTVID
@ AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_MOTIONPIXELS
@ AV_CODEC_ID_DSICINVIDEO
@ AV_CODEC_ID_FFWAVESYNTH
@ AV_CODEC_ID_INTERPLAY_VIDEO
@ AV_CODEC_ID_WMALOSSLESS
@ AV_CODEC_ID_TRUEMOTION2
@ AV_CODEC_ID_SIMBIOSIS_IMX
@ AV_CODEC_ID_SCREENPRESSO
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Alias for avcodec_receive_frame_flags(avctx, frame, 0).
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
Modify width and height values so that they will result in a memory buffer that is acceptable for the...
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
@ AVDISCARD_ALL
discard all
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVCodecParserContext * av_parser_init(enum AVCodecID codec_id)
void av_parser_close(AVCodecParserContext *s)
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
void av_log_set_level(int level)
Set the log level.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
int av_image_fill_plane_sizes(size_t sizes[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4])
Fill plane sizes for an image with pixel format pix_fmt and height height.
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
@ AV_PICTURE_TYPE_I
Intra.
common internal api header.
#define FF_SANE_NB_CHANNELS
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
Memory handling functions.
main external API structure.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int64_t pos
Byte position of currently parsed frame in stream.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int64_t pos
byte position in stream, -1 if unknown
static const uint64_t FUZZ_TAG
static uint64_t max_alloc_pixels
static uint64_t alloc_pixels
const uint32_t maxiteration
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
static int fuzz_get_buffer2(AVCodecContext *ctx, AVFrame *frame, int flags)
static void error(const char *err)
static const FFCodec * AVCodecInitialize(enum AVCodecID codec_id)
static int subtitle_handler(AVCodecContext *avctx, AVFrame *unused, int *got_sub_ptr, const AVPacket *avpkt)
const FFCodec * codec_list[]
static int fuzz_video_get_buffer(AVCodecContext *ctx, AVFrame *frame)
static int audio_video_handler(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *dummy)