[FFmpeg-cvslog] avformat: fix overflows during bit rate calculation

Andreas Cadhalpun git at videolan.org
Wed Dec 14 02:10:20 EET 2016


ffmpeg | branch: master | Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com> | Tue Dec 13 00:38:25 2016 +0100| [ad5807f8aa883bee5431186dc1f24c5435d722d3] | committer: Andreas Cadhalpun

avformat: fix overflows during bit rate calculation

The bit_rate field has type int64_t since commit
7404f3bdb90e6a5dcb59bc0a091e2c5c038e557d.

Reviewed-by: Paul B Mahol <onemda at gmail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ad5807f8aa883bee5431186dc1f24c5435d722d3
---

 libavformat/adxdec.c         | 2 +-
 libavformat/aiffdec.c        | 4 ++--
 libavformat/apc.c            | 2 +-
 libavformat/bfi.c            | 2 +-
 libavformat/electronicarts.c | 2 +-
 libavformat/iff.c            | 2 +-
 libavformat/soxdec.c         | 2 +-
 libavformat/voc_packet.c     | 2 +-
 libavformat/vqf.c            | 2 +-
 libavformat/wsddec.c         | 2 +-
 10 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavformat/adxdec.c b/libavformat/adxdec.c
index 0315ecb..a271e2a 100644
--- a/libavformat/adxdec.c
+++ b/libavformat/adxdec.c
@@ -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);
 
diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 59e969d..9e7a39c 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -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;
diff --git a/libavformat/apc.c b/libavformat/apc.c
index a4dcf66..b180a50 100644
--- a/libavformat/apc.c
+++ b/libavformat/apc.c
@@ -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;
 
diff --git a/libavformat/bfi.c b/libavformat/bfi.c
index ef4c17d..6c98e33 100644
--- a/libavformat/bfi.c
+++ b/libavformat/bfi.c
@@ -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;
diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index 80ce4c6..30eb723 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -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 *
diff --git a/libavformat/iff.c b/libavformat/iff.c
index bf44170..29fb7bf 100644
--- a/libavformat/iff.c
+++ b/libavformat/iff.c
@@ -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;
diff --git a/libavformat/soxdec.c b/libavformat/soxdec.c
index 0a937e7..12a94c8 100644
--- a/libavformat/soxdec.c
+++ b/libavformat/soxdec.c
@@ -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 *
diff --git a/libavformat/voc_packet.c b/libavformat/voc_packet.c
index 0d56436..4f60467 100644
--- a/libavformat/voc_packet.c
+++ b/libavformat/voc_packet.c
@@ -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;
diff --git a/libavformat/vqf.c b/libavformat/vqf.c
index 969fbef..841840e 100644
--- a/libavformat/vqf.c
+++ b/libavformat/vqf.c
@@ -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
         {
diff --git a/libavformat/wsddec.c b/libavformat/wsddec.c
index 9ca0576..81a4dcc 100644
--- a/libavformat/wsddec.c
+++ b/libavformat/wsddec.c
@@ -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;
 



More information about the ffmpeg-cvslog mailing list