53 static void error(
const char *err)
55 fprintf(stderr,
"%s", err);
67 error(
"Failed to find decoder");
71 #if defined(FUZZ_FFMPEG_VIDEO)
72 #define decode_handler avcodec_decode_video2
73 #elif defined(FUZZ_FFMPEG_AUDIO)
74 #define decode_handler avcodec_decode_audio4
75 #elif defined(FUZZ_FFMPEG_SUBTITLE)
81 if (ret >= 0 && *got_sub_ptr)
86 #define decode_handler subtitle_handler
88 #error "Specify encoder type" // To catch mistakes
101 error(
"Failed memory allocation");
109 if (needed > FDB->
size_) {
114 error(
"Failed memory allocation");
122 memcpy(FDB->
data_, data, size);
126 memset(FDB->
data_ + size, 0, padd);
135 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
149 error(
"Failed memory allocation");
161 error(
"Failed memory allocation");
165 while (data < end && it < maxiteration) {
167 while (data +
sizeof(fuzz_tag) < end) {
168 if (data[0] == (fuzz_tag & 0xFF) && *(
const uint64_t *)(data) == fuzz_tag)
172 if (data +
sizeof(fuzz_tag) > end)
175 FDBPrepare(&buffer, &avpkt, last, data - last);
176 data +=
sizeof(fuzz_tag);
180 while (avpkt.
size > 0 && it++ < maxiteration) {
182 int ret = decode_handler(ctx, frame, &got_frame, &avpkt);
183 if (ret <= 0 || ret > avpkt.
size)
196 decode_handler(ctx, frame, &got_frame, &avpkt);
197 }
while (got_frame == 1 && it++ < maxiteration);
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
void av_log_set_level(int level)
Set the log level.
const uint32_t maxiteration
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
void FDBDesroy(FuzzDataBuffer *FDB)
#define FF_INPUT_BUFFER_PADDING_SIZE
#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.
static const uint64_t FUZZ_TAG
#define AV_LOG_PANIC
Something went really wrong and we will crash now.
static av_cold int end(AVCodecContext *avctx)
static AVCodec * AVCodecInitialize(enum AVCodecID codec_id)
AVCodecID
Identify the syntax and semantics of the bitstream.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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.
static void error(const char *err)
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Libavcodec external API header.
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.
void FDBCreate(FuzzDataBuffer *FDB)
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
void FDBRealloc(FuzzDataBuffer *FDB, size_t size)
void FDBPrepare(FuzzDataBuffer *FDB, AVPacket *dst, const uint8_t *data, size_t size)
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.