diff mbox

[FFmpeg-devel] avformat/utils: Never store negative values in last_IP_duration

Message ID 20181013011310.4320-1-michael@niedermayer.cc
State Accepted
Commit 079d1a7175c4b881631a7e7f449c4c13b761cdeb
Headers show

Commit Message

Michael Niedermayer Oct. 13, 2018, 1:13 a.m. UTC
Fixes: integer overflow compute_pkt_fields()
Fixes: compute_pkt_usan

Reported-by: Thomas Guilbert <tguilbert@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/utils.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Oct. 18, 2018, 12:23 a.m. UTC | #1
On Sat, Oct 13, 2018 at 03:13:10AM +0200, Michael Niedermayer wrote:
> Fixes: integer overflow compute_pkt_fields()
> Fixes: compute_pkt_usan
> 
> Reported-by: Thomas Guilbert <tguilbert@chromium.org>
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/utils.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

will apply

[...]
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index fa3699daef..93e588ee1e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1352,7 +1352,7 @@  static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
 
             /* This is tricky: the dts must be incremented by the duration
              * of the frame we are displaying, i.e. the last I- or P-frame. */
-            if (st->last_IP_duration == 0)
+            if (st->last_IP_duration == 0 && (uint64_t)pkt->duration <= INT32_MAX)
                 st->last_IP_duration = pkt->duration;
             if (pkt->dts != AV_NOPTS_VALUE)
                 st->cur_dts = pkt->dts + st->last_IP_duration;
@@ -1364,7 +1364,8 @@  static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
                 next_pts != AV_NOPTS_VALUE)
                 pkt->pts = next_dts;
 
-            st->last_IP_duration = pkt->duration;
+            if ((uint64_t)pkt->duration <= INT32_MAX)
+                st->last_IP_duration = pkt->duration;
             st->last_IP_pts      = pkt->pts;
             /* Cannot compute PTS if not present (we can compute it only
              * by knowing the future. */