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).
This commit is contained in:
Mark Nauwelaerts 2011-08-29 15:13:56 +02:00
parent 3968dc7688
commit 5ea19b0696

View file

@ -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)) {