diff mbox series

[FFmpeg-devel,3/3] avcodec/wmalosslessdec: Simplify flushing, avoid NULL + 0

Message ID GV1P250MB07377E5B451D34B6D438967B8F549@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit bf8e40ae0d5975d3c18ef326ae62fe9052e746f6
Headers show
Series [FFmpeg-devel,1/3] avcodec/wmavoice: Don't initialize GetBitContext with buf == NULL | expand

Commit Message

Andreas Rheinhardt Sept. 28, 2022, 6:43 p.m. UTC
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 <andreas.rheinhardt@outlook.com>
---
 libavcodec/wmalosslessdec.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
diff mbox series

Patch

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)