diff --git a/ffplay.c b/ffplay.c
index c44264ed4a7db73420492d19cca0c0a41ef74fa1..8c1ea313784c351b68d9e9eab76b90b447b4ab4e 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1582,6 +1582,9 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic)
     int i, w, h, stride[4];
     unsigned edge;
 
+    if(av_image_check_size(w, h, 0, codec))
+        return -1;
+
     if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES)
         perms |= AV_PERM_NEG_LINESIZES;