From aa308b18d78990cab50c163560a3ec44ddbdf159 Mon Sep 17 00:00:00 2001
From: Dale Curtis <dalecurtis@chromium.org>
Date: Wed, 14 Aug 2024 23:20:56 +0000
Subject: [PATCH] [h264] Use small padding with the checked bitstream reader.

MAX_MBPAIR_SIZE was added in 23f5cff92cdcfa55a735c458fcb5f95c0e0f3b1f
to prevent CABAC/CAVLC overread issues. It adds 256kb of padding to
RBSP allocations. AFAICT it seems unnecessary with the checked
bitstream reader. Dropping this padding is a substantial memory
improvement for constrained devices.

782865bf3094e36cbb4bd9cfacda252307e6589d removed the small padding
when AV_CODEC_FLAG2_FAST was set, but I don't have access to that
fuzzer test case to check this patch.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavcodec/h264dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index c77d8f42db..07bcb0c389 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -613,7 +613,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
     }
 
     ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc, h->nal_length_size,
-                                avctx->codec_id, 0, 0);
+                                avctx->codec_id, UNCHECKED_BITSTREAM_READER ? 0 : 1, 0);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR,
                "Error splitting the input into NAL units.\n");
-- 
2.46.0.76.ge559c4bf1a-goog

