avformat/oggparsespeex: Check frames_per_packet and packet_size
authorMichael Niedermayer <michael@niedermayer.cc>
Sat, 3 Dec 2016 02:40:55 +0000 (03:40 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sun, 4 Dec 2016 19:25:15 +0000 (20:25 +0100)
The speex specification does not seem to restrict these values, thus
the limits where choosen so as to avoid multiplicative overflow

Fixes undefined behavior
Fixes: 635422.ogg

Found-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit afcf15b0dbb4b6429be5083e50b296cdca61875e)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/oggparsespeex.c

index c86b127..3440a50 100644 (file)
@@ -76,6 +76,13 @@ static int speex_header(AVFormatContext *s, int idx) {
 
         spxp->packet_size  = AV_RL32(p + 56);
         frames_per_packet  = AV_RL32(p + 64);
+        if (spxp->packet_size < 0 ||
+            frames_per_packet < 0 ||
+            spxp->packet_size * (int64_t)frames_per_packet > INT32_MAX / 256) {
+            av_log(s, AV_LOG_ERROR, "invalid packet_size, frames_per_packet %d %d\n", spxp->packet_size, frames_per_packet);
+            spxp->packet_size = 0;
+            return AVERROR_INVALIDDATA;
+        }
         if (frames_per_packet)
             spxp->packet_size *= frames_per_packet;