9cd9f3
diff -up libwebp-0.3.0/src/dec/buffer.c.old libwebp-0.3.0/src/dec/buffer.c
9cd9f3
--- libwebp-0.3.0/src/dec/buffer.c.old	2021-05-17 12:37:43.268514218 +0200
9cd9f3
+++ libwebp-0.3.0/src/dec/buffer.c	2021-05-17 12:38:27.435859390 +0200
9cd9f3
@@ -35,6 +35,11 @@ static int IsValidColorspace(int webp_cs
9cd9f3
   return (webp_csp_mode >= MODE_RGB && webp_csp_mode < MODE_LAST);
9cd9f3
 }
9cd9f3
 
9cd9f3
+// strictly speaking, the very last (or first, if flipped) row
9cd9f3
+// doesn't require padding.
9cd9f3
+#define MIN_BUFFER_SIZE(WIDTH, HEIGHT, STRIDE)       \
9cd9f3
+    ((uint64_t)(STRIDE) * ((HEIGHT) - 1) + (WIDTH))
9cd9f3
+
9cd9f3
 static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
9cd9f3
   int ok = 1;
9cd9f3
   const WEBP_CSP_MODE mode = buffer->colorspace;
9cd9f3
@@ -64,7 +69,9 @@ static VP8StatusCode CheckDecBuffer(cons
9cd9f3
     }
9cd9f3
   } else {    // RGB checks
9cd9f3
     const WebPRGBABuffer* const buf = &buffer->u.RGBA;
9cd9f3
-    const uint64_t size = (uint64_t)buf->stride * height;
9cd9f3
+    const int stride = abs(buf->stride);
9cd9f3
+    const uint64_t size =
9cd9f3
+        MIN_BUFFER_SIZE(width * kModeBpp[mode], height, stride);
9cd9f3
     ok &= (size <= buf->size);
9cd9f3
     ok &= (buf->stride >= width * kModeBpp[mode]);
9cd9f3
     ok &= (buf->rgba != NULL);