diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 82689da..dec6e37 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -432,6 +432,10 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data,
             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;
@@ -452,12 +456,12 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data,
 
         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));
     }
