From bf8e40ae0d5975d3c18ef326ae62fe9052e746f6 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 27 Sep 2022 19:39:44 +0200 Subject: [PATCH] avcodec/wmalosslessdec: Simplify flushing, avoid NULL + 0 Return immediately if not enough leftover bits are available when flushing. This is simpler and also avoids an init_get_bits(gb, NULL, 0) (which currently leads to NULL + 0, which is UB; this affects the lossless-wma(|-1|-2|-rawtile) FATE tests). Signed-off-by: Andreas Rheinhardt --- libavcodec/wmalosslessdec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 5112b763fa..d545d848e2 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -1192,16 +1192,15 @@ static int decode_packet(AVCodecContext *avctx, AVFrame *rframe, s->frame->nb_samples = 0; - if (!buf_size && s->num_saved_bits > get_bits_count(&s->gb)) { + if (!buf_size) { s->packet_done = 0; + if (s->num_saved_bits <= get_bits_count(&s->gb)) + return 0; if (!decode_frame(s)) s->num_saved_bits = 0; } else if (s->packet_done || s->packet_loss) { s->packet_done = 0; - if (!buf_size) - return 0; - s->next_packet_start = buf_size - FFMIN(avctx->block_align, buf_size); buf_size = FFMIN(avctx->block_align, buf_size); s->buf_bit_size = buf_size << 3; @@ -1299,7 +1298,7 @@ static int decode_packet(AVCodecContext *avctx, AVFrame *rframe, s->packet_offset = get_bits_count(gb) & 7; - return (s->packet_loss) ? AVERROR_INVALIDDATA : buf_size ? get_bits_count(gb) >> 3 : 0; + return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; } static void flush(AVCodecContext *avctx)