From 34130afe8bdf89bbd2e913845db1f8fed0dd4b0a Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 18 Aug 2017 23:50:13 +0000 Subject: [PATCH] anim_encode: fix integer overflow calculate the file duration using unsigned math. this could still result in an incorrect average duration calculation if there were multiple rollovers. caching the duration is an option if it was desirable to support such an extreme case. Change-Id: I3875d94d081fec947c03a857055df6e27ff5351d --- src/mux/anim_encode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mux/anim_encode.c b/src/mux/anim_encode.c index 2dbb39bd..33c076bc 100644 --- a/src/mux/anim_encode.c +++ b/src/mux/anim_encode.c @@ -1536,7 +1536,8 @@ int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, WebPData* webp_data) { if (!enc->got_null_frame_ && enc->in_frame_count_ > 1 && enc->count_ > 0) { // set duration of the last frame to be avg of durations of previous frames. - const double delta_time = enc->prev_timestamp_ - enc->first_timestamp_; + const double delta_time = + (uint32_t)enc->prev_timestamp_ - enc->first_timestamp_; const int average_duration = (int)(delta_time / (enc->in_frame_count_ - 1)); if (!IncreasePreviousDuration(enc, average_duration)) { return 0;