Hi On Sat, Apr 16, 2016 at 12:12:41AM +0200, Pawel Golinski wrote: > There are some afl specific macros inside, > to make the example usable with afl fuzzer. > --- > doc/examples/fffuzz.c | 370 > ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 370 insertions(+) > create mode 100644 doc/examples/fffuzz.c > > diff --git a/doc/examples/fffuzz.c b/doc/examples/fffuzz.c > new file mode 100644 > index 0000000..6672f42 > --- /dev/null > +++ b/doc/examples/fffuzz.c > @@ -0,0 +1,370 @@ > +/* > + * Copyright (c) 2012 Stefano Sabatini > + * Copyright (c) 2015 Andreas Cadhalpun
there was a review comment about this, please do not ignore review comments for reference; >>> <kierank> the first patch in the patchset is my patch so I can't review it >>> would suggest to me that he should be listed in the Copyright too also when at this, please make sure the author metadata in the commits is correct, i dont know who wrote what also the code is still not hooked up to the build system [...] > +/** > + * @file > + * Demuxing and decoding (a codec/format combination) example. > + * > + * This can be useful for fuzz testing. > + * @example ddcf.c > + */ > + > +#include <libavutil/avstring.h> > +#include <libavutil/imgutils.h> > +#include <libavutil/samplefmt.h> > +#include <libavutil/timestamp.h> > +#include <libavformat/avformat.h> > + > +/* needed for decoding video */ > +static int width, height; > +static enum AVPixelFormat pix_fmt; > +static uint8_t *video_dst_data[4] = {NULL}; > +static int video_dst_linesize[4]; > +static int video_dst_bufsize; > + > +static int decode_packet(AVCodecContext *dec_ctx, FILE *dst_file, AVFrame > *frame, int *got_frame, int *frame_count, AVPacket *pkt) > +{ > + int ret = -1; > + *got_frame = 0; > + AVSubtitle sub; > + unsigned i, j, k, l; > + > + if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { > + /* decode video frame */ > + ret = avcodec_decode_video2(dec_ctx, frame, got_frame, pkt); > + if (ret < 0) { > + fprintf(stderr, "Error decoding video frame (%s)\n", > av_err2str(ret)); > + return ret; > + } > + > + if (*got_frame) { > + > + if (frame->width != width || frame->height != height || > + frame->format != pix_fmt) { > + fprintf(stderr, "Error: input video width/height/format > changed:\n" > + "old: width = %d, height = %d, format = %s\n" > + "new: width = %d, height = %d, format = %s\n", > + width, height, av_get_pix_fmt_name(pix_fmt), > + dec_ctx->width, dec_ctx->height, > + av_get_pix_fmt_name(dec_ctx->pix_fmt)); > + return -1; > + } > + > + printf("video_frame n:%d coded_n:%d pts:%s\n", > + *frame_count, frame->coded_picture_number, > + av_ts2timestr(frame->pts, &dec_ctx->time_base)); > + > + /* copy decoded frame to destination buffer: > + * this is required since rawvideo expects non aligned data */ > + av_image_copy(video_dst_data, video_dst_linesize, > + (const uint8_t **)(frame->data), frame->linesize, > + pix_fmt, width, height); > + *frame_count += 1; > + > + /* write to rawvideo file */ > + fwrite(video_dst_data[0], 1, video_dst_bufsize, dst_file); > + } > + } else if (dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { > + /* decode audio frame */ > + ret = avcodec_decode_audio4(dec_ctx, frame, got_frame, pkt); > + if (ret < 0) { > + fprintf(stderr, "Error decoding audio frame (%s)\n", > av_err2str(ret)); > + return ret; > + } > + /* Some audio decoders decode only part of the packet, and have to be > + * called again with the remainder of the packet data. > + * Sample: fate-suite/lossless-audio/luckynight-partial.shn > + * Also, some decoders might over-read the packet. */ > + ret = FFMIN(ret, pkt->size); overreads should not be ignored silently [...] > +static int open_codec_context(AVCodecContext **dec_ctx, AVFormatContext > *fmt_ctx, char *codec) > +{ > + int ret = -1; > + AVCodec *dec = avcodec_find_decoder_by_name(codec); > + AVDictionary *opts = NULL; > + unsigned int i; > + > + for (i = 0; i < fmt_ctx->nb_streams && i < INT_MAX; i += 1) { > + if (fmt_ctx->streams[i]->codec) { > + if (!dec || (fmt_ctx->streams[i]->codec->codec_id == dec->id)) { > + *dec_ctx = fmt_ctx->streams[i]->codec; > + ret = 0; > + break; > + } > + } > + } > + > + if (ret < 0) { > + fprintf(stderr, "Could not find stream\n"); > + } else { > + /* find decoder for the stream */ > + if (!dec) > + dec = avcodec_find_decoder((*dec_ctx)->codec_id); > + if (!dec) { > + fprintf(stderr, "Failed to find decoder\n"); > + return -1; > + } > + > + /* Init the decoders, with or without reference counting */ > + av_dict_set(&opts, "refcounted_frames", "1", 0); > + av_dict_set(&opts, "strict", "-2", 0); > + av_dict_set(&opts, "codec_whitelist", codec, 0); > + av_dict_set(&opts, "thread_type", "slice", 0); missing failure checks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Everything should be made as simple as possible, but not simpler. -- Albert Einstein
signature.asc
Description: Digital signature
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel