[FFmpeg-devel] [PATCH] avcodec/speexdec: check for sane s->frame_size values

James Almer jamrial at gmail.com
Fri Feb 16 16:19:25 EET 2024


Fixes heap buffer overflows

Reported-by: sploitem <sploitem at gmail.com>
Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/speexdec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/speexdec.c b/libavcodec/speexdec.c
index 51c5834769..4d8052d585 100644
--- a/libavcodec/speexdec.c
+++ b/libavcodec/speexdec.c
@@ -1420,7 +1420,10 @@ static int parse_speex_extradata(AVCodecContext *avctx,
     if (s->nb_channels <= 0 || s->nb_channels > 2)
         return AVERROR_INVALIDDATA;
     s->bitrate = bytestream_get_le32(&buf);
-    s->frame_size = (1 + (s->mode > 0)) * bytestream_get_le32(&buf);
+    s->frame_size = bytestream_get_le32(&buf);
+    if (s->frame_size < NB_FRAME_SIZE << (s->mode > 0))
+        return AVERROR_INVALIDDATA;
+    s->frame_size *= 1 + (s->mode > 0);
     s->vbr = bytestream_get_le32(&buf);
     s->frames_per_packet = bytestream_get_le32(&buf);
     if (s->frames_per_packet <= 0 ||
-- 
2.43.1



More information about the ffmpeg-devel mailing list