diff mbox

[FFmpeg-devel] avformat/utils: Discard huge timestamps which would cause overflows if used in basic computations

Message ID 20160925215400.4042-1-michael@niedermayer.cc
State Accepted
Commit e936c8d176efd1a0a41e22df24564b1178c79ea9
Headers show

Commit Message

Michael Niedermayer Sept. 25, 2016, 9:54 p.m. UTC
Allowing larger timestamps makes it impossible to calculate basic things like the
difference of 2 timestamps or their sum without checking each individual computation for
overflow.
This should avoid a significant number of overflow checks

Fixes Ticket5136

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/utils.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Michael Niedermayer Oct. 26, 2016, 5:47 p.m. UTC | #1
On Sun, Sep 25, 2016 at 11:54:00PM +0200, Michael Niedermayer wrote:
> Allowing larger timestamps makes it impossible to calculate basic things like the
> difference of 2 timestamps or their sum without checking each individual computation for
> overflow.
> This should avoid a significant number of overflow checks
> 
> Fixes Ticket5136
> 
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/utils.c | 6 ++++++
>  1 file changed, 6 insertions(+)

applied

[...]
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3e0f57d..d227e24 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -833,6 +833,12 @@  int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
             continue;
         }
 
+        if (   (pkt->dts != AV_NOPTS_VALUE && (pkt->dts <= INT64_MIN/2 || pkt->dts >= INT64_MAX/2))
+            || (pkt->pts != AV_NOPTS_VALUE && (pkt->pts <= INT64_MIN/2 || pkt->pts >= INT64_MAX/2))) {
+            av_log(s, AV_LOG_WARNING, "Ignoring huge timestamps %"PRId64" %"PRId64"\n", pkt->dts, pkt->pts);
+            pkt->dts = pkt->pts = AV_NOPTS_VALUE;
+        }
+
         st = s->streams[pkt->stream_index];
 
         if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) {