Check that the required plane pointers and only those are set up. Signed-off-by: Reimar Döffinger <reimar.doeffin...@gmx.de> --- libavcodec/utils.c | 20 ++++++++++++++++++++ libavutil/frame.h | 3 +++ 2 files changed, 23 insertions(+)
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index af21cdd..1b6397c 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -853,6 +853,24 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) return ff_init_buffer_info(avctx, frame); } +static void validate_avframe_allocation(const AVCodecContext *avctx, AVFrame *frame) +{ + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { + int i; + int num_planes = av_pix_fmt_count_planes(frame->format); + for (i = 0; i < num_planes; i++) { + av_assert0(frame->data[i]); + } + // for formats without data like hwaccel allow + // pointers to be non-NULL. + for (i = num_planes; num_planes > 0 && i < num_planes; i++) { + if (frame->data[i]) + av_log(avctx, AV_LOG_ERROR, "Buffer returned by get_buffer2() did not zero unused plane pointers\n"); + frame->data[i] = NULL; + } + } +} + static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) { const AVHWAccel *hwaccel = avctx->hwaccel; @@ -885,6 +903,8 @@ static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) avctx->sw_pix_fmt = avctx->pix_fmt; ret = avctx->get_buffer2(avctx, frame, flags); + if (ret >= 0) + validate_avframe_allocation(avctx, frame); end: if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 56001a8..76a8123 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -187,6 +187,9 @@ typedef struct AVFrame { * see avcodec_align_dimensions2(). Some filters and swscale can read * up to 16 bytes beyond the planes, if these filters are to be used, * then 16 extra bytes must be allocated. + * + * NOTE: Except for hwaccel formats, pointers not needed by the format + * MUST be set to NULL. */ uint8_t *data[AV_NUM_DATA_POINTERS]; -- 2.7.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel