avformat: fix overflows during bit rate calculation
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Mon, 12 Dec 2016 23:38:25 +0000 (00:38 +0100)
committerAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Wed, 14 Dec 2016 00:06:55 +0000 (01:06 +0100)
The bit_rate field has type int64_t since commit
7404f3bdb90e6a5dcb59bc0a091e2c5c038e557d.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
libavformat/adxdec.c
libavformat/aiffdec.c
libavformat/apc.c
libavformat/bfi.c
libavformat/electronicarts.c
libavformat/iff.c
libavformat/soxdec.c
libavformat/voc_packet.c
libavformat/vqf.c
libavformat/wsddec.c

index 0315ecb..a271e2a 100644 (file)
@@ -116,7 +116,7 @@ static int adx_read_header(AVFormatContext *s)
 
     par->codec_type  = AVMEDIA_TYPE_AUDIO;
     par->codec_id    = s->iformat->raw_codec_id;
-    par->bit_rate    = par->sample_rate * par->channels * BLOCK_SIZE * 8LL / BLOCK_SAMPLES;
+    par->bit_rate    = (int64_t)par->sample_rate * par->channels * BLOCK_SIZE * 8LL / BLOCK_SAMPLES;
 
     avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, par->sample_rate);
 
index 59e969d..9e7a39c 100644 (file)
@@ -181,7 +181,7 @@ static int get_aiff_header(AVFormatContext *s, int size,
         par->block_align = (av_get_bits_per_sample(par->codec_id) * par->channels) >> 3;
 
     if (aiff->block_duration) {
-        par->bit_rate = par->sample_rate * (par->block_align << 3) /
+        par->bit_rate = (int64_t)par->sample_rate * (par->block_align << 3) /
                         aiff->block_duration;
     }
 
@@ -318,7 +318,7 @@ static int aiff_read_header(AVFormatContext *s)
                     st->codecpar->block_align = 35;
                 }
                 aiff->block_duration = 160;
-                st->codecpar->bit_rate = st->codecpar->sample_rate * (st->codecpar->block_align << 3) /
+                st->codecpar->bit_rate = (int64_t)st->codecpar->sample_rate * (st->codecpar->block_align << 3) /
                                          aiff->block_duration;
             }
             break;
index a4dcf66..b180a50 100644 (file)
@@ -65,7 +65,7 @@ static int apc_read_header(AVFormatContext *s)
     }
 
     st->codecpar->bits_per_coded_sample = 4;
-    st->codecpar->bit_rate = st->codecpar->bits_per_coded_sample * st->codecpar->channels
+    st->codecpar->bit_rate = (int64_t)st->codecpar->bits_per_coded_sample * st->codecpar->channels
                           * st->codecpar->sample_rate;
     st->codecpar->block_align = 1;
 
index ef4c17d..6c98e33 100644 (file)
@@ -108,7 +108,7 @@ static int bfi_read_header(AVFormatContext * s)
     astream->codecpar->channel_layout  = AV_CH_LAYOUT_MONO;
     astream->codecpar->bits_per_coded_sample = 8;
     astream->codecpar->bit_rate        =
-        astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample;
+        (int64_t)astream->codecpar->sample_rate * astream->codecpar->bits_per_coded_sample;
     avio_seek(pb, chunk_header - 3, SEEK_SET);
     avpriv_set_pts_info(astream, 64, 1, astream->codecpar->sample_rate);
     return 0;
index 80ce4c6..30eb723 100644 (file)
@@ -557,7 +557,7 @@ static int ea_read_header(AVFormatContext *s)
         st->codecpar->channels              = ea->num_channels;
         st->codecpar->sample_rate           = ea->sample_rate;
         st->codecpar->bits_per_coded_sample = ea->bytes * 8;
-        st->codecpar->bit_rate              = st->codecpar->channels *
+        st->codecpar->bit_rate              = (int64_t)st->codecpar->channels *
                                               st->codecpar->sample_rate *
                                               st->codecpar->bits_per_coded_sample / 4;
         st->codecpar->block_align           = st->codecpar->channels *
index bf44170..29fb7bf 100644 (file)
@@ -748,7 +748,7 @@ static int iff_read_header(AVFormatContext *s)
         }
 
         st->codecpar->bits_per_coded_sample = av_get_bits_per_sample(st->codecpar->codec_id);
-        st->codecpar->bit_rate = st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample;
+        st->codecpar->bit_rate = (int64_t)st->codecpar->channels * st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample;
         st->codecpar->block_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample;
         if (st->codecpar->codec_tag == ID_DSD && st->codecpar->block_align <= 0)
             return AVERROR_INVALIDDATA;
index 0a937e7..12a94c8 100644 (file)
@@ -113,7 +113,7 @@ static int sox_read_header(AVFormatContext *s)
 
     st->codecpar->sample_rate           = sample_rate;
     st->codecpar->bits_per_coded_sample = 32;
-    st->codecpar->bit_rate              = st->codecpar->sample_rate *
+    st->codecpar->bit_rate              = (int64_t)st->codecpar->sample_rate *
                                           st->codecpar->bits_per_coded_sample *
                                           st->codecpar->channels;
     st->codecpar->block_align           = st->codecpar->bits_per_coded_sample *
index 0d56436..4f60467 100644 (file)
@@ -126,7 +126,7 @@ ff_voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size)
         }
     }
 
-    par->bit_rate = par->sample_rate * par->channels * par->bits_per_coded_sample;
+    par->bit_rate = (int64_t)par->sample_rate * par->channels * par->bits_per_coded_sample;
 
     if (max_size <= 0)
         max_size = 2048;
index 969fbef..841840e 100644 (file)
@@ -140,7 +140,7 @@ static int vqf_read_header(AVFormatContext *s)
                 return AVERROR_INVALIDDATA;
             }
 
-            st->codecpar->bit_rate = read_bitrate * 1000;
+            st->codecpar->bit_rate = (int64_t)read_bitrate * 1000;
             break;
         case MKTAG('D','S','I','Z'): // size of compressed data
         {
index 9ca0576..81a4dcc 100644 (file)
@@ -128,7 +128,7 @@ static int wsd_read_header(AVFormatContext *s)
     st->codecpar->sample_rate = avio_rb32(pb) / 8;
     avio_skip(pb, 4);
     st->codecpar->channels    = avio_r8(pb) & 0xF;
-    st->codecpar->bit_rate    = st->codecpar->channels * st->codecpar->sample_rate * 8LL;
+    st->codecpar->bit_rate    = (int64_t)st->codecpar->channels * st->codecpar->sample_rate * 8LL;
     if (!st->codecpar->channels)
         return AVERROR_INVALIDDATA;