61 static void error(
const char *err)
63 fprintf(stderr,
"%s", err);
74 error(
"Failed to find decoder");
83 if (ret >= 0 && *got_sub_ptr)
98 error(
"Failed memory allocation");
106 if (needed > FDB->
size_) {
111 error(
"Failed memory allocation");
119 memcpy(FDB->
data_, data, size);
123 memset(FDB->
data_ + size, 0, padd);
132 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
141 int *got_picture_ptr,
147 #ifdef FFMPEG_DECODER
148 #define DECODER_SYMBOL0(CODEC) ff_##CODEC##_decoder
149 #define DECODER_SYMBOL(CODEC) DECODER_SYMBOL0(CODEC)
150 extern AVCodec DECODER_SYMBOL(FFMPEG_DECODER);
151 codec_list[0] = &DECODER_SYMBOL(FFMPEG_DECODER);
154 c = &DECODER_SYMBOL(FFMPEG_DECODER);
170 if (!ctx || !parser_avctx)
171 error(
"Failed memory allocation");
178 ctx->
width = bytestream2_get_le32(&gbc);
179 ctx->
height = bytestream2_get_le32(&gbc);
180 ctx->
bit_rate = bytestream2_get_le64(&gbc);
183 if (bytestream2_get_byte(&gbc) & 1)
202 error(
"Failed memory allocation");
208 while (data +
sizeof(fuzz_tag) < end) {
209 if (data[0] == (fuzz_tag & 0xFF) &&
AV_RN64(data) == fuzz_tag)
213 if (data +
sizeof(fuzz_tag) > end)
216 FDBPrepare(&buffer, &parsepkt, last, data - last);
217 data +=
sizeof(fuzz_tag);
220 while (parsepkt.
size > 0) {
226 parsepkt.
pts, parsepkt.
dts, parsepkt.
pos);
227 parsepkt.
data += ret;
228 parsepkt.
size -= ret;
245 int ret = decode_handler(ctx, frame, &got_frame, &avpkt);
250 if (ret <= 0 || ret > avpkt.
size)
266 decode_handler(ctx, frame, &got_frame, &avpkt);
const uint32_t maxiteration
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * 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.
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.
static void FDBCreate(FuzzDataBuffer *FDB)
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
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)
av_cold void avcodec_register(AVCodec *codec)
Register the codec codec and initialize libavcodec.
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.
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
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t max_pixels
The number of pixels per image to maximally accept.
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...
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.
void av_parser_close(AVCodecParserContext *s)
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...
main external API structure.
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.
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
static void FDBPrepare(FuzzDataBuffer *FDB, AVPacket *dst, const uint8_t *data, size_t size)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#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_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...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static void FDBDesroy(FuzzDataBuffer *FDB)
static void FDBRealloc(FuzzDataBuffer *FDB, size_t size)
This structure stores compressed data.
int key_frame
Set by parser to 1 for key frames and 0 for non-key frames.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...