54 static void error(
const char *err)
56 fprintf(stderr,
"%s", err);
68 error(
"Failed to find decoder");
72 #if defined(FUZZ_FFMPEG_VIDEO)
73 #define decode_handler avcodec_decode_video2
74 #elif defined(FUZZ_FFMPEG_AUDIO)
75 #define decode_handler avcodec_decode_audio4
76 #elif defined(FUZZ_FFMPEG_SUBTITLE)
82 if (ret >= 0 && *got_sub_ptr)
87 #define decode_handler subtitle_handler
89 #error "Specify encoder type" // To catch mistakes
102 error(
"Failed memory allocation");
110 if (needed > FDB->
size_) {
115 error(
"Failed memory allocation");
123 memcpy(FDB->
data_, data, size);
127 memset(FDB->
data_ + size, 0, padd);
136 static const uint64_t
FUZZ_TAG = 0x4741542D5A5A5546ULL;
150 error(
"Failed memory allocation");
162 error(
"Failed memory allocation");
166 while (data < end && it < maxiteration) {
168 while (data +
sizeof(fuzz_tag) < end) {
169 if (data[0] == (fuzz_tag & 0xFF) &&
AV_RN64(data) == fuzz_tag)
173 if (data +
sizeof(fuzz_tag) > end)
176 FDBPrepare(&buffer, &avpkt, last, data - last);
177 data +=
sizeof(fuzz_tag);
181 while (avpkt.
size > 0 && it++ < maxiteration) {
183 int ret = decode_handler(ctx, frame, &got_frame, &avpkt);
188 if (ret <= 0 || ret > avpkt.
size)
203 decode_handler(ctx, frame, &got_frame, &avpkt);
204 }
while (got_frame == 1 && it++ < maxiteration);
const uint32_t 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.
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)
Decode a subtitle message.
#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.
void FDBCreate(FuzzDataBuffer *FDB)
#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)
void FDBPrepare(FuzzDataBuffer *FDB, AVPacket *dst, const uint8_t *data, size_t size)
static const uint64_t FUZZ_TAG
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.
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.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
static AVCodec * AVCodecInitialize(enum AVCodecID codec_id)
void FDBDesroy(FuzzDataBuffer *FDB)
static void error(const char *err)
Libavcodec external API header.
enum AVMediaType codec_type
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.
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)
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.