From 4ed634c65b4bc7bc53686da17fce8505bfdcdf9f Mon Sep 17 00:00:00 2001
From: Arnaud Vrac <avrac@freebox.fr>
Date: Tue, 2 Sep 2025 15:09:56 +0200
Subject: [PATCH 1/6] avcodec/alac: fixes


diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index f91288e97c..3f932ec6e8 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -438,6 +438,10 @@ static int alac_decode_frame(AVCodecContext *avctx, AVFrame *frame,
             got_end = 1;
             break;
         }
+
+        if (ch >= alac->channels)
+            break;
+
         if (element > TYPE_CPE && element != TYPE_LFE) {
             avpriv_report_missing_feature(avctx, "Syntax element %d", element);
             return AVERROR_PATCHWELCOME;
@@ -458,12 +462,12 @@ static int alac_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
         ch += channels;
     }
-    if (!got_end) {
+    if (!got_end && ch < alac->channels) {
         av_log(avctx, AV_LOG_ERROR, "no end tag found. incomplete packet.\n");
         return AVERROR_INVALIDDATA;
     }
 
-    if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {
+    if (avpkt->size * 8 - get_bits_count(&alac->gb) >= 32) {
         av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",
                avpkt->size * 8 - get_bits_count(&alac->gb));
     }
-- 
2.51.0

