OSDN Git Service

xmv: Add more sanity checks for parameters read from the bitstream
authorMartin Storsjö <martin@martin.st>
Mon, 16 Sep 2013 18:27:49 +0000 (21:27 +0300)
committerMartin Storsjö <martin@martin.st>
Tue, 17 Sep 2013 17:09:25 +0000 (20:09 +0300)
Since the number of channels is multiplied by 36 and assigned to
to a uint16_t, make sure this calculation didn't overflow. (In
certain cases the calculation could overflow leaving the
truncated block_align at 0, leading to divisions by zero later.)

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
Signed-off-by: Martin Storsjö <martin@martin.st>
libavformat/xmv.c

index bc7c3c9..2b2fd45 100644 (file)
@@ -43,6 +43,8 @@
                            XMV_AUDIO_ADPCM51_FRONTCENTERLOW | \
                            XMV_AUDIO_ADPCM51_REARLEFTRIGHT)
 
+#define XMV_BLOCK_ALIGN_SIZE 36
+
 typedef struct XMVAudioTrack {
     uint16_t compression;
     uint16_t channels;
@@ -207,7 +209,7 @@ static int xmv_read_header(AVFormatContext *s)
         track->bit_rate      = track->bits_per_sample *
                                track->sample_rate *
                                track->channels;
-        track->block_align   = 36 * track->channels;
+        track->block_align   = XMV_BLOCK_ALIGN_SIZE * track->channels;
         track->block_samples = 64;
         track->codec_id      = ff_wav_codec_get_id(track->compression,
                                                    track->bits_per_sample);
@@ -224,7 +226,8 @@ static int xmv_read_header(AVFormatContext *s)
             av_log(s, AV_LOG_WARNING, "Unsupported 5.1 ADPCM audio stream "
                                       "(0x%04X)\n", track->flags);
 
-        if (!track->channels || !track->sample_rate) {
+        if (!track->channels || !track->sample_rate ||
+             track->channels >= UINT16_MAX / XMV_BLOCK_ALIGN_SIZE) {
             av_log(s, AV_LOG_ERROR, "Invalid parameters for audio track %d.\n",
                    audio_track);
             ret = AVERROR_INVALIDDATA;