From d7d4e45bc38f363af5cd2ab6ce25b7b0202ce628 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 9 Apr 2025 22:04:46 +0200
Subject: [PATCH 08/10] avcodec/hq_hqa: Check available date before allocating
 frame

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/hq_hqa.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index 11388fb9fc..26493b1e1c 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -149,6 +149,9 @@ static int hq_decode_frame(HQContext *ctx, AVFrame *pic, GetByteContext *gbc,
         av_log(ctx->avctx, AV_LOG_VERBOSE, "HQ Profile %d\n", prof_num);
     }
 
+    if (bytestream2_get_bytes_left(gbc) < 3 * (profile->num_slices + 1))
+        return AVERROR_INVALIDDATA;
+
     ctx->avctx->coded_width         = FFALIGN(profile->width,  16);
     ctx->avctx->coded_height        = FFALIGN(profile->height, 16);
     ctx->avctx->width               = profile->width;
-- 
2.45.2