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

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Sep 28 21:43:00 EEST 2022


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 at outlook.com>
---
 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)
-- 
2.34.1



More information about the ffmpeg-devel mailing list