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)
99 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
106 uint64_t ec_pixels = 0;
107 uint64_t nb_samples = 0;
109 int *got_picture_ptr,
112 uint64_t keyframes = 0;
116 #ifdef FFMPEG_DECODER 117 #define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder 118 #define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC) 119 extern AVCodec DECODER_SYMBOL(FFMPEG_DECODER);
120 codec_list[0] = &DECODER_SYMBOL(FFMPEG_DECODER);
123 #if FFMPEG_DECODER == tiff || FFMPEG_DECODER == tdsc 124 extern AVCodec DECODER_SYMBOL(mjpeg);
125 codec_list[1] = &DECODER_SYMBOL(mjpeg);
129 c = &DECODER_SYMBOL(FFMPEG_DECODER);
174 case AV_CODEC_ID_RTV1:
maxpixels /= 16;
break;
190 if (!ctx || !parser_avctx)
191 error(
"Failed memory allocation");
205 ctx->
width = bytestream2_get_le32(&gbc);
206 ctx->
height = bytestream2_get_le32(&gbc);
207 ctx->
bit_rate = bytestream2_get_le64(&gbc);
210 flags = bytestream2_get_byte(&gbc);
226 extradata_size = bytestream2_get_le32(&gbc);
228 ctx->
sample_rate = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
230 ctx->
block_align = bytestream2_get_le32(&gbc) & 0x7FFFFFFF;
231 ctx->
codec_tag = bytestream2_get_le32(&gbc);
237 keyframes = bytestream2_get_le64(&gbc);
240 ctx->
idct_algo = bytestream2_get_byte(&gbc) % 25;
246 av_dict_set_int(&opts,
"cons_noisegen", bytestream2_get_byte(&gbc) & 1, 0);
247 av_dict_set_int(&opts,
"heavy_compr", bytestream2_get_byte(&gbc) & 1, 0);
248 av_dict_set_int(&opts,
"target_level", (
int)(bytestream2_get_byte(&gbc) % 32) - 31, 0);
249 av_dict_set_int(&opts,
"dmix_mode", (
int)(bytestream2_get_byte(&gbc) % 4) - 1, 0);
255 if (extradata_size < size) {
280 error(
"Failed memory allocation");
286 while (data < end && it < maxiteration) {
288 while (data +
sizeof(fuzz_tag) < end) {
289 if (data[0] == (fuzz_tag & 0xFF) &&
AV_RN64(data) == fuzz_tag)
293 if (data +
sizeof(fuzz_tag) > end)
298 error(
"Failed memory allocation");
299 memcpy(parsepkt.
data, last, data - last);
301 keyframes = (keyframes >> 2) + (keyframes<<62);
302 data +=
sizeof(fuzz_tag);
305 while (parsepkt.
size > 0) {
311 parsepkt.
pts, parsepkt.
dts, parsepkt.
pos);
315 error(
"Failed memory allocation");
318 error(
"Failed memory allocation");
320 parsepkt.
data += ret;
321 parsepkt.
size -= ret;
335 while (avpkt.
size > 0 && it++ < maxiteration) {
337 int ret = decode_handler(ctx, frame, &got_frame, &avpkt);
339 ec_pixels += (ctx->
width + 32LL) * (ctx->
height + 32LL);
340 if (it > 20 || ec_pixels > 4 * ctx->
max_pixels)
343 goto maximums_reached;
347 goto maximums_reached;
349 if (ret <= 0 || ret > avpkt.
size)
367 decode_handler(ctx, frame, &got_frame, &avpkt);
368 }
while (got_frame == 1 && it++ < maxiteration);
370 fprintf(stderr,
"pixels decoded: %"PRId64
", samples decoded: %"PRId64
", iterations: %d\n", ec_pixels, nb_samples, it);
#define FF_SANE_NB_CHANNELS
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
const uint32_t maxiteration
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
This structure describes decoded (raw) audio or video data.
int64_t bit_rate
the average bitrate
int64_t pos
byte position in stream, -1 if unknown
void av_log_set_level(int level)
Set the log level.
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
attribute_deprecated int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
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.
static av_cold int end(AVCodecContext *avctx)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
av_cold void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
const uint32_t * codec_tags
List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
void avcodec_register_all(void)
Register all the codecs, parsers and bitstream filters which were enabled at configuration time...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
static const uint64_t FUZZ_TAG
AVCodecID
Identify the syntax and semantics of the bitstream.
int64_t pos
Byte position of currently parsed frame in stream.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int error_concealment
error concealment flags
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
simple assert() macros that are a bit more flexible than ISO C assert().
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int64_t max_pixels
The number of pixels per image to maximally accept.
const uint64_t maxpixels_per_frame
int flags
A combination of AV_PKT_FLAG values.
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 err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
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.
static AVCodec * AVCodecInitialize(enum AVCodecID codec_id)
int width
picture width / height.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
void av_parser_close(AVCodecParserContext *s)
#define AV_EF_EXPLODE
abort decoding on minor error detection
static void error(const char *err)
static int subtitle_handler(AVCodecContext *avctx, void *frame, int *got_sub_ptr, AVPacket *avpkt)
AVCodecParserContext * av_parser_init(int codec_id)
Libavcodec external API header.
enum AVMediaType codec_type
attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
int sample_rate
samples per second
#define AV_CODEC_FLAG2_FAST
Allow non spec compliant speedup tricks.
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
void avsubtitle_free(AVSubtitle *sub)
Free all allocated data in the given subtitle struct.
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
int64_t max_samples
The number of samples per frame to maximally accept.
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
attribute_deprecated int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define flags(name, subs,...)
#define AV_PKT_FLAG_DISCARD
Flag is used to discard packets which are required to maintain valid decoder state but are not requir...
common internal api header.
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...
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int channels
number of audio channels
int flags2
AV_CODEC_FLAG2_*.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define FF_CODEC_TAGS_END
AVCodec.codec_tags termination value.
void av_force_cpu_flags(int arg)
Disables cpu detection and forces the specified flags.
uint64_t maxsamples_per_frame
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
This structure stores compressed data.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
int nb_samples
number of audio samples (per channel) described by this frame
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...