From 51b7f356fddead46572c4bf65c4c3e07478bff75 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Wed, 9 Apr 2025 22:10:16 +0200
Subject: [PATCH 10/10] avcodec/hq_hqa: Check size before initializing
 GetByteContext

Enables the compiler to optimize the buf_size assert
in bytestream2_init() away.

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

diff --git a/libavcodec/hq_hqa.c b/libavcodec/hq_hqa.c
index cc3bdc5894..42804e2c2b 100644
--- a/libavcodec/hq_hqa.c
+++ b/libavcodec/hq_hqa.c
@@ -329,11 +329,11 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic,
     int ret;
     unsigned tag;
 
-    bytestream2_init(gbc, avpkt->data, avpkt->size);
-    if (bytestream2_get_bytes_left(gbc) < 4 + 4) {
+    if (avpkt->size < 4 + 4) {
         av_log(avctx, AV_LOG_ERROR, "Frame is too small (%d).\n", avpkt->size);
         return AVERROR_INVALIDDATA;
     }
+    bytestream2_init(gbc, avpkt->data, avpkt->size);
 
     info_tag = bytestream2_peek_le32u(gbc);
     if (info_tag == MKTAG('I', 'N', 'F', 'O')) {
-- 
2.45.2