Go to the documentation of this file.
67 static void error(
const char *err)
69 fprintf(stderr,
"%s", err);
80 error(
"Failed to find decoder");
85 int *got_sub_ptr,
const AVPacket *avpkt)
89 if (
ret >= 0 && *got_sub_ptr)
98 *got_frame =
ret >= 0;
105 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
109 ptrdiff_t linesize1[4];
130 for (
i = 0;
i < 4 &&
size[
i];
i++) {
149 switch (
ctx->codec_type) {
162 uint64_t maxpixels_per_frame = 4096 * 4096;
165 uint64_t maxsamples_per_frame = 256*1024*32;
168 const uint8_t *last =
data;
171 uint64_t ec_pixels = 0;
172 uint64_t nb_samples = 0;
174 int *got_picture_ptr,
177 uint64_t keyframes = 0;
178 uint64_t flushpattern = -1;
182 #ifdef FFMPEG_DECODER
183 #define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
184 #define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC)
185 extern FFCodec DECODER_SYMBOL(FFMPEG_DECODER);
186 codec_list[0] = &DECODER_SYMBOL(FFMPEG_DECODER);
188 #if FFMPEG_DECODER == tiff || FFMPEG_DECODER == tdsc
189 extern FFCodec DECODER_SYMBOL(mjpeg);
193 c = &DECODER_SYMBOL(FFMPEG_DECODER);
321 maxsamples_per_frame =
FFMIN(maxsamples_per_frame, maxsamples);
322 maxpixels_per_frame =
FFMIN(maxpixels_per_frame , maxpixels);
326 if (!
ctx || !parser_avctx)
327 error(
"Failed memory allocation");
329 if (
ctx->max_pixels == 0 ||
ctx->max_pixels > maxpixels_per_frame)
330 ctx->max_pixels = maxpixels_per_frame;
332 ctx->max_samples = maxsamples_per_frame;
339 uint64_t request_channel_layout;
344 ctx->width = bytestream2_get_le32(&gbc);
345 ctx->height = bytestream2_get_le32(&gbc);
347 ctx->bits_per_coded_sample = bytestream2_get_le32(&gbc);
349 flags = bytestream2_get_byte(&gbc);
367 extradata_size = bytestream2_get_le32(&gbc);
369 ctx->sample_rate = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
371 ctx->block_align = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
372 ctx->codec_tag = bytestream2_get_le32(&gbc);
378 keyframes = bytestream2_get_le64(&gbc);
379 request_channel_layout = bytestream2_get_le64(&gbc);
381 ctx->idct_algo = bytestream2_get_byte(&gbc) % 25;
382 flushpattern = bytestream2_get_le64(&gbc);
387 switch (
ctx->codec_id) {
400 if (request_channel_layout) {
401 switch (
ctx->codec_id) {
407 if (request_channel_layout & ~INT64_MIN) {
410 error(
"Failed memory allocation");
411 av_strlcatf(downmix_layout, 19,
"0x%"PRIx64, request_channel_layout & ~INT64_MIN);
423 flags64 = bytestream2_get_le64(&gbc);
435 ctx->workaround_bugs = bytestream2_get_le32(&gbc);
441 if (extradata_size <
size) {
443 if (
ctx->extradata) {
444 ctx->extradata_size = extradata_size;
450 ctx->width =
ctx->height = 0;
470 if (!
frame || !avpkt || !parsepkt)
471 error(
"Failed memory allocation");
476 while (
data +
sizeof(fuzz_tag) < end) {
481 if (
data +
sizeof(fuzz_tag) > end)
486 error(
"Failed memory allocation");
487 memcpy(parsepkt->
data, last,
data - last);
489 keyframes = (keyframes >> 2) + (keyframes<<62);
490 data +=
sizeof(fuzz_tag);
493 while (parsepkt->
size > 0) {
499 parsepkt->
pts, parsepkt->
dts, parsepkt->
pos);
500 if (avpkt->
data == parsepkt->
data) {
503 error(
"Failed memory allocation");
506 error(
"Failed memory allocation");
522 if (!(flushpattern & 7))
524 flushpattern = (flushpattern >> 3) + (flushpattern << 61);
528 decode_more =
ret >= 0;
530 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
531 if (
it > 20 || ec_pixels > 4 *
ctx->max_pixels) {
532 ctx->error_concealment = 0;
535 if (ec_pixels > maxpixels)
536 goto maximums_reached;
544 int ret = decode_handler(
ctx,
frame, &got_frame, avpkt);
546 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
547 if (
it > 20 || ec_pixels > 4 *
ctx->max_pixels) {
548 ctx->error_concealment = 0;
551 if (ec_pixels > maxpixels)
552 goto maximums_reached;
557 nb_samples +=
ctx->max_samples;
560 if (nb_samples > maxsamples)
561 goto maximums_reached;
563 if (ret <= 0 || ret > avpkt->
size)
569 decode_more = avpkt->
size > 0;
571 decode_more =
ret >= 0;
587 decode_handler(
ctx,
frame, &got_frame, avpkt);
590 if (nb_samples > maxsamples)
594 fprintf(stderr,
"pixels decoded: %"PRId64
", samples decoded: %"PRId64
", iterations: %d\n", ec_pixels, nb_samples,
it);
@ AV_CODEC_ID_TRUEMOTION2
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
@ AV_CODEC_ID_INTERPLAY_ACM
uint8_t * data
The data buffer.
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
#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_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int strict_std_compliance
Allow non-standard and experimental extension.
@ AV_CODEC_ID_SCREENPRESSO
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
@ AV_CODEC_ID_DSICINVIDEO
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
uint8_t max_lowres
maximum value for lowres supported by the decoder
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
AVCodec p
The public AVCodec.
AVCodecParserContext * av_parser_init(int codec_id)
@ AV_CODEC_ID_FFWAVESYNTH
#define FF_CODEC_TAGS_END
FFCodec.codec_tags termination value.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_CODEC_ID_DVB_SUBTITLE
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const AVPacket *avpkt)
Decode a subtitle message.
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
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.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder or encoder (when the AV_CODEC_FLAG_RECON_FRAME flag is used...
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...
@ AVDISCARD_ALL
discard all
static const uint64_t FUZZ_TAG
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
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.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
@ AV_CODEC_ID_WMALOSSLESS
@ AV_CODEC_ID_MOTIONPIXELS
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
@ AV_PICTURE_TYPE_I
Intra.
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
static void error(const char *err)
AVCodecID
Identify the syntax and semantics of the bitstream.
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
const FFCodec * codec_list[]
#define AV_NUM_DATA_POINTERS
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
int flags
A combination of AV_PKT_FLAG values.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
void av_log_set_level(int level)
Set the log level.
int nb_samples
number of audio samples (per channel) described by this frame
int64_t pos
Byte position of currently parsed frame in stream.
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t ** extended_data
pointers to the data planes/channels.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
@ AV_CODEC_ID_BETHSOFTVID
static const FFCodec * AVCodecInitialize(enum AVCodecID codec_id)
static int fuzz_video_get_buffer(AVCodecContext *ctx, AVFrame *frame)
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
static int audio_video_handler(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *dummy)
#define AV_INPUT_BUFFER_PADDING_SIZE
#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
Decoding only.
static int fuzz_get_buffer2(AVCodecContext *ctx, AVFrame *frame, int flags)
int debug
Flags to enable debugging.
main external API structure.
const uint32_t * codec_tags
List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
@ AV_CODEC_ID_SIMBIOSIS_IMX
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.
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.
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s it
This structure stores compressed data.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int64_t pos
byte position in stream, -1 if unknown
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
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...
#define FF_SANE_NB_CHANNELS
static int subtitle_handler(AVCodecContext *avctx, AVFrame *unused, int *got_sub_ptr, const AVPacket *avpkt)
const uint32_t maxiteration
void av_parser_close(AVCodecParserContext *s)