diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index 65168d52be..8cc270acbb 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -157,6 +157,8 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int heigh
 
     /* restore top left pixel */
     val     = loco_get_rice(&rc);
+    if (val == INT_MIN)
+        return AVERROR_INVALIDDATA;
     data[0] = 128 + val;
     /* restore top line */
     for (i = 1; i < width; i++) {