64 static void error(
const char *err)
66 fprintf(stderr,
"%s", err);
77 error(
"Failed to find decoder");
86 if (ret >= 0 && *got_sub_ptr)
95 *got_frame = ret >= 0;
107 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
114 uint64_t ec_pixels = 0;
115 uint64_t nb_samples = 0;
117 int *got_picture_ptr,
120 uint64_t keyframes = 0;
121 uint64_t flushpattern = -1;
125 #ifdef FFMPEG_DECODER
126 #define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
127 #define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC)
128 extern AVCodec DECODER_SYMBOL(FFMPEG_DECODER);
129 codec_list[0] = &DECODER_SYMBOL(FFMPEG_DECODER);
131 #if FFMPEG_DECODER == tiff || FFMPEG_DECODER == tdsc
132 extern AVCodec DECODER_SYMBOL(mjpeg);
136 c = &DECODER_SYMBOL(FFMPEG_DECODER);
210 if (!
ctx || !parser_avctx)
211 error(
"Failed memory allocation");
224 ctx->width = bytestream2_get_le32(&gbc);
225 ctx->height = bytestream2_get_le32(&gbc);
227 ctx->bits_per_coded_sample = bytestream2_get_le32(&gbc);
229 flags = bytestream2_get_byte(&gbc);
245 extradata_size = bytestream2_get_le32(&gbc);
247 ctx->sample_rate = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
249 ctx->block_align = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
250 ctx->codec_tag = bytestream2_get_le32(&gbc);
256 keyframes = bytestream2_get_le64(&gbc);
257 ctx->request_channel_layout = bytestream2_get_le64(&gbc);
259 ctx->idct_algo = bytestream2_get_byte(&gbc) % 25;
260 flushpattern = bytestream2_get_le64(&gbc);
263 switch (
ctx->codec_id) {
275 if (extradata_size <
size) {
277 if (
ctx->extradata) {
278 ctx->extradata_size = extradata_size;
284 ctx->width =
ctx->height = 0;
301 if (!
frame || !avpkt || !parsepkt)
302 error(
"Failed memory allocation");
307 while (
data +
sizeof(fuzz_tag) < end) {
312 if (
data +
sizeof(fuzz_tag) > end)
317 error(
"Failed memory allocation");
318 memcpy(parsepkt->
data, last,
data - last);
320 keyframes = (keyframes >> 2) + (keyframes<<62);
321 data +=
sizeof(fuzz_tag);
324 while (parsepkt->
size > 0) {
330 parsepkt->
pts, parsepkt->
dts, parsepkt->
pos);
331 if (avpkt->
data == parsepkt->
data) {
334 error(
"Failed memory allocation");
337 error(
"Failed memory allocation");
339 parsepkt->
data += ret;
340 parsepkt->
size -= ret;
341 parsepkt->
pos += ret;
353 if (!(flushpattern & 7))
355 flushpattern = (flushpattern >> 3) + (flushpattern << 61);
359 decode_more = ret >= 0;
361 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
362 if (it > 20 || ec_pixels > 4 *
ctx->max_pixels)
363 ctx->error_concealment = 0;
365 goto maximums_reached;
373 int ret = decode_handler(
ctx,
frame, &got_frame, avpkt);
375 ec_pixels += (
ctx->width + 32LL) * (
ctx->height + 32LL);
376 if (it > 20 || ec_pixels > 4 *
ctx->max_pixels)
377 ctx->error_concealment = 0;
379 goto maximums_reached;
384 nb_samples +=
ctx->max_samples;
388 goto maximums_reached;
390 if (ret <= 0 || ret > avpkt->
size)
396 decode_more = avpkt->
size > 0;
398 decode_more = ret >= 0;
414 decode_handler(
ctx,
frame, &got_frame, avpkt);
417 fprintf(stderr,
"pixels decoded: %"PRId64
", samples decoded: %"PRId64
", iterations: %d\n", ec_pixels, nb_samples, it);
simple assert() macros that are a bit more flexible than ISO C assert().
Libavcodec external API header.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#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 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...
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define flags(name, subs,...)
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
static float sub(float src0, float src1)
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
AVCodecID
Identify the syntax and semantics of the bitstream.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
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_INTERPLAY_ACM
@ AV_CODEC_ID_MOTIONPIXELS
@ AV_CODEC_ID_FFWAVESYNTH
@ AV_CODEC_ID_WMALOSSLESS
@ AV_CODEC_ID_TRUEMOTION2
@ AV_CODEC_ID_SCREENPRESSO
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
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(int 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_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
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.
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_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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...
@ AV_PICTURE_TYPE_I
Intra.
common internal api header.
#define FF_CODEC_TAGS_END
AVCodec.codec_tags termination value.
#define FF_SANE_NB_CHANNELS
main external API structure.
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.
const uint32_t * codec_tags
List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
int strict_std_compliance
Allow non-standard and experimental extension.
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
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
uint64_t maxsamples_per_frame
uint64_t maxpixels_per_frame
static const uint64_t FUZZ_TAG
const uint32_t maxiteration
static int subtitle_handler(AVCodecContext *avctx, void *frame, int *got_sub_ptr, AVPacket *avpkt)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
static void error(const char *err)
static AVCodec * AVCodecInitialize(enum AVCodecID codec_id)
static int audio_video_handler(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *dummy)