diff --git a/libavcodec/indeo3.c b/libavcodec/indeo3.c
index 633bb300e96fda8522313d25a16c7664c0ba6829..004b618ff09b6b89e542017f35601b17aad554a1 100644
--- a/libavcodec/indeo3.c
+++ b/libavcodec/indeo3.c
@@ -893,8 +893,7 @@ static int decode_frame_headers(Indeo3DecodeContext *ctx, AVCodecContext *avctx,
 
     if (ctx->data_size == 16)
         return 4;
-    if (ctx->data_size > buf_size)
-        ctx->data_size = buf_size;
+    ctx->data_size = FFMIN(ctx->data_size, buf_size - 16);
 
     bytestream2_skip(&gb, 3); // skip reserved byte and checksum