aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2016-04-26 19:17:19 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2016-04-29 14:23:41 +0200
commit72d8ce1cf276ab8c0d43b2ae953c3722a5c76b03 (patch)
tree9d10ce643e526bf5f1d2cc782ab7c399443e074a
parent19fcdd0c2f4c62695961413c9456ca525678879d (diff)
downloadffmpeg-72d8ce1cf276ab8c0d43b2ae953c3722a5c76b03.tar.gz
avcodec/ttaenc: Reallocate packet if its too small
Fixes assertion failure Fixes Ticket5394 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 005c61c6b8982f977e415aa69d2d2b42e6b7f3f2) Conflicts: libavcodec/ttaenc.c
-rw-r--r--libavcodec/ttaenc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/libavcodec/ttaenc.c b/libavcodec/ttaenc.c
index ccd41a90c9..37624a9c62 100644
--- a/libavcodec/ttaenc.c
+++ b/libavcodec/ttaenc.c
@@ -114,9 +114,12 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
{
TTAEncContext *s = avctx->priv_data;
PutBitContext pb;
- int ret, i, out_bytes, cur_chan = 0, res = 0, samples = 0;
+ int ret, i, out_bytes, cur_chan, res, samples;
+ int64_t pkt_size = frame->nb_samples * 2LL * avctx->channels * s->bps;
- if ((ret = ff_alloc_packet2(avctx, avpkt, frame->nb_samples * 2 * avctx->channels * s->bps)) < 0)
+pkt_alloc:
+ cur_chan = 0, res = 0, samples = 0;
+ if ((ret = ff_alloc_packet2(avctx, avpkt, pkt_size)) < 0)
return ret;
init_put_bits(&pb, avpkt->data, avpkt->size);
@@ -174,6 +177,14 @@ static int tta_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
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);
+ }
do {
if (unary > 31) {
put_bits(&pb, 31, 0x7FFFFFFF);