[FFmpeg-cvslog] avformat/utils: use av_reduce() to simplify code and avoid overflow in ff_compute_frame_duration()

Michael Niedermayer git at videolan.org
Wed Oct 15 18:29:15 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Oct 15 18:23:21 2014 +0200| [a92192d2e4f7ff3078b128592f6673089b221cc4] | committer: Michael Niedermayer

avformat/utils: use av_reduce() to simplify code and avoid overflow in ff_compute_frame_duration()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/utils.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 20e1b21..909c7de 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -726,17 +726,18 @@ void ff_compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, AVStrea
             *pnum = st->time_base.num;
             *pden = st->time_base.den;
         } else if (codec_framerate.den * 1000LL > codec_framerate.num) {
-            *pnum = codec_framerate.den;
-            *pden = codec_framerate.num;
-
-            *pden *= st->codec->ticks_per_frame;
             av_assert0(st->codec->ticks_per_frame);
+            av_reduce(pnum, pden,
+                      codec_framerate.den,
+                      codec_framerate.num * (int64_t)st->codec->ticks_per_frame,
+                      INT_MAX);
+
             if (pc && pc->repeat_pict) {
                 av_assert0(s->iformat); // this may be wrong for interlaced encoding but its not used for that case
-                if (*pnum > INT_MAX / (1 + pc->repeat_pict))
-                    *pden /= 1 + pc->repeat_pict;
-                else
-                    *pnum *= 1 + pc->repeat_pict;
+                av_reduce(pnum, pden,
+                          (*pnum) * (1LL + pc->repeat_pict),
+                          (*pden),
+                          INT_MAX);
             }
             /* If this codec can be interlaced or progressive then we need
              * a parser to compute duration of a packet. Thus if we have



More information about the ffmpeg-cvslog mailing list