[FFmpeg-devel] [PATCH] avcodec/decode: don't increase hw frame size

Timo Rothenpieler timo at rothenpieler.org
Sun Nov 12 15:01:51 EET 2017


In case the hw frames context does not return way too large frames,
but slightly smaller ones(for example height being 1080, while
coded_height is 1088), this causes failures because various code will
try to read/write beyond the frame size.
---
 libavcodec/decode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index a7f1e23fc2..0a5ec6a21b 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1491,8 +1491,8 @@ int avcodec_default_get_buffer2(AVCodecContext *avctx, AVFrame *frame, int flags
 
     if (avctx->hw_frames_ctx) {
         ret = av_hwframe_get_buffer(avctx->hw_frames_ctx, frame, 0);
-        frame->width  = avctx->coded_width;
-        frame->height = avctx->coded_height;
+        frame->width  = FFMIN(avctx->coded_width, frame->width);
+        frame->height = FFMIN(avctx->coded_height, frame->height);
         return ret;
     }
 
-- 
2.14.2



More information about the ffmpeg-devel mailing list