This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch release/9.1
in repository ffmpeg.

commit 35f6a7c6e104790e95501519a28394137ee3e954
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Thu Nov 5 03:41:23 2026 +0100
Commit:     Michael Niedermayer <[email protected]>
CommitDate: Sun Nov 15 02:46:01 2026 +0100

    avcodec/ttaenc: check the packet space for each sample and the CRC
    
    Fixes: Assertion failure
    Fixes: bAfKKmQm4ZDe
    Fixes: AISLE-2026-0150-00078
    Assertion failure Replicated through UnModified FFmpeg
    
    Found-by: Joshua Rogers (AISLE)
    (cherry picked from commit 29a629e788c4343ff2e923095b8f38769fe2e470)
    Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavcodec/ttaenc.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c
index 46751ff3ca..4bef53a20f 100644
--- a/libavcodec/ttaenc.c
+++ b/libavcodec/ttaenc.c
@@ -90,13 +90,15 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket 
*avpkt,
     TTAEncContext *s = avctx->priv_data;
     PutBitContext pb;
     int ret, i, out_bytes, cur_chan, res, samples;
-    int64_t pkt_size =  frame->nb_samples * 2LL * avctx->ch_layout.nb_channels 
* s->bps;
+    int64_t pkt_size =  frame->nb_samples * 2LL * avctx->ch_layout.nb_channels 
* s->bps + 4;
+    int64_t bits_left;
 
 pkt_alloc:
     cur_chan = 0, res = 0, samples = 0;
     if ((ret = ff_alloc_packet(avctx, avpkt, pkt_size)) < 0)
         return ret;
     init_put_bits(&pb, avpkt->data, avpkt->size);
+    bits_left = 8 * (pkt_size - 4);
 
     // init per channel states
     for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
@@ -109,7 +111,7 @@ pkt_alloc:
         TTAChannel *c = &s->ch_ctx[cur_chan];
         TTAFilter *filter = &c->filter;
         TTARice *rice = &c->rice;
-        uint32_t k, unary, outval;
+        uint32_t k, unary = 0, outval;
         int32_t value, temp;
 
         value = get_sample(frame, samples++, avctx->sample_fmt);
@@ -153,23 +155,25 @@ pkt_alloc:
                 rice->k1++;
 
             unary = 1 + (outval >> k);
-            if (unary + 100LL > put_bits_left(&pb)) {
-                if (pkt_size < INT_MAX/2) {
-                    pkt_size *= 2;
-                    av_packet_unref(avpkt);
-                    goto pkt_alloc;
-                } else
-                    return AVERROR(ENOMEM);
+        }
+
+        if (unary + 1LL + k > bits_left) {
+            if (pkt_size < INT_MAX/2) {
+                pkt_size *= 2;
+                av_packet_unref(avpkt);
+                goto pkt_alloc;
+            } else
+                return AVERROR(ENOMEM);
+        }
+        bits_left -= unary + 1 + k;
+        while (unary) {
+            if (unary > 31) {
+                put_bits(&pb, 31, 0x7FFFFFFF);
+                unary -= 31;
+            } else {
+                put_bits(&pb, unary, (1U << unary) - 1);
+                unary = 0;
             }
-            do {
-                if (unary > 31) {
-                    put_bits(&pb, 31, 0x7FFFFFFF);
-                    unary -= 31;
-                } else {
-                    put_bits(&pb, unary, (1U << unary) - 1);
-                    unary = 0;
-                }
-            } while (unary);
         }
 
         put_bits(&pb, 1, 0);

-- 
To stop receiving notification emails like this one, please contact
[email protected].
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to