]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/gifdec: truncate too big width/height for invalid gif files
authorPaul B Mahol <onemda@gmail.com>
Mon, 10 Dec 2018 12:32:10 +0000 (13:32 +0100)
committerPaul B Mahol <onemda@gmail.com>
Mon, 10 Dec 2018 16:56:32 +0000 (17:56 +0100)
Fixes #6874.

libavcodec/gifdec.c

index 54f1d4c0ba7fdbf8129f21d535a731c8ccd6851d..2115da163f620243739f9ffedb38a953e0c3b21a 100644 (file)
@@ -179,12 +179,20 @@ static int gif_read_image(GifState *s, AVFrame *frame)
     }
 
     /* verify that all the image is inside the screen dimensions */
-    if (!width || width > s->screen_width || left >= s->screen_width) {
-        av_log(s->avctx, AV_LOG_ERROR, "Invalid image width.\n");
+    if (!width || width > s->screen_width) {
+        av_log(s->avctx, AV_LOG_WARNING, "Invalid image width: %d, truncating.\n", width);
+        width = s->screen_width;
+    }
+    if (left >= s->screen_width) {
+        av_log(s->avctx, AV_LOG_ERROR, "Invalid left position: %d.\n", left);
         return AVERROR_INVALIDDATA;
     }
-    if (!height || height > s->screen_height || top >= s->screen_height) {
-        av_log(s->avctx, AV_LOG_ERROR, "Invalid image height.\n");
+    if (!height || height > s->screen_height) {
+        av_log(s->avctx, AV_LOG_WARNING, "Invalid image height: %d, truncating.\n", height);
+        height = s->screen_height;
+    }
+    if (top >= s->screen_height) {
+        av_log(s->avctx, AV_LOG_ERROR, "Invalid top position: %d.\n", top);
         return AVERROR_INVALIDDATA;
     }
     if (left + width > s->screen_width) {