From 5ea19b0696123c1050946d317535736dc584c66a Mon Sep 17 00:00:00 2001 From: Mark Nauwelaerts Date: Mon, 29 Aug 2011 15:13:56 +0200 Subject: [PATCH] qtdemux: avoid overflow wraparound in timestamp when adding durations Do some type juggling to avoid overflow, while still allowing for 'negative' durations (which would need a wraparound effect). --- gst/isomp4/qtdemux.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c index 036e509c33..99564e828e 100644 --- a/gst/isomp4/qtdemux.c +++ b/gst/isomp4/qtdemux.c @@ -317,7 +317,7 @@ struct _QtDemuxStream guint32 stts_samples; guint32 n_sample_times; guint32 stts_sample_index; - guint32 stts_time; + guint64 stts_time; guint32 stts_duration; /* stss */ gboolean stss_present; @@ -5623,8 +5623,8 @@ done2: for (i = stream->stts_index; i < n_sample_times; i++) { guint32 stts_samples; - guint32 stts_duration; - guint32 stts_time; + gint32 stts_duration; + gint64 stts_time; if (stream->stts_sample_index >= stream->stts_samples || !stream->stts_sample_index) { @@ -5654,7 +5654,9 @@ done2: cur->timestamp = stts_time; cur->duration = stts_duration; - stts_time += stts_duration; + /* avoid 32-bit wrap-around, + * but still mind possible 'negative' duration */ + stts_time += (gint64) stts_duration; cur++; if (G_UNLIKELY (cur > last)) {