diff mbox

[FFmpeg-devel] lavf/utils: Do not overflow in update_initial_timestamps().

Message ID 201609241528.36266.cehoyos@ag.or.at
State Rejected
Headers show

Commit Message

Carl Eugen Hoyos Sept. 24, 2016, 1:28 p.m. UTC
Hi!

Attached patch hopefully fixes ticket #5136.

Please review, Carl Eugen
From 09a31f8f6584f0c97443fd6edc7fcf7142b6a6ff Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Sat, 24 Sep 2016 15:26:21 +0200
Subject: [PATCH] lavf/utils: Do not overflow in update_initial_timestamps().

Fixes ticket #5136.
---
 libavformat/utils.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Sept. 25, 2016, 6:59 p.m. UTC | #1
On Sat, Sep 24, 2016 at 03:28:36PM +0200, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch hopefully fixes ticket #5136.
> 
> Please review, Carl Eugen

>  utils.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 519f209901429efaf9dffec381290a6a83573deb  0001-lavf-utils-Do-not-overflow-in-update_initial_timesta.patch
> From 09a31f8f6584f0c97443fd6edc7fcf7142b6a6ff Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Sat, 24 Sep 2016 15:26:21 +0200
> Subject: [PATCH] lavf/utils: Do not overflow in update_initial_timestamps().
> 
> Fixes ticket #5136.
> ---
>  libavformat/utils.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

probably ok
it might be ultimately easier to reject demuxer output that has
timestamps close to INT64 MAX/MIN instead of protecting all computations
one by one though

thx

[...]
Carl Eugen Hoyos Sept. 25, 2016, 7:04 p.m. UTC | #2
2016-09-25 20:59 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:
> On Sat, Sep 24, 2016 at 03:28:36PM +0200, Carl Eugen Hoyos wrote:
>> Hi!
>>
>> Attached patch hopefully fixes ticket #5136.
>>
>> Please review, Carl Eugen
>
>>  utils.c |    4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>> 519f209901429efaf9dffec381290a6a83573deb
>> 0001-lavf-utils-Do-not-overflow-in-update_initial_timesta.patch
>> From 09a31f8f6584f0c97443fd6edc7fcf7142b6a6ff Mon Sep 17 00:00:00 2001
>> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
>> Date: Sat, 24 Sep 2016 15:26:21 +0200
>> Subject: [PATCH] lavf/utils: Do not overflow in
>> update_initial_timestamps().
>>
>> Fixes ticket #5136.
>> ---
>>  libavformat/utils.c |    4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> probably ok
> it might be ultimately easier to reject demuxer output that has
> timestamps close to INT64 MAX/MIN instead of protecting all
> computations one by one though

I don't disagree but I am probably unable to improve the patch.
Do you want me to apply?

Carl Eugen
Michael Niedermayer Sept. 25, 2016, 9:55 p.m. UTC | #3
On Sun, Sep 25, 2016 at 09:04:30PM +0200, Carl Eugen Hoyos wrote:
> 2016-09-25 20:59 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:
> > On Sat, Sep 24, 2016 at 03:28:36PM +0200, Carl Eugen Hoyos wrote:
> >> Hi!
> >>
> >> Attached patch hopefully fixes ticket #5136.
> >>
> >> Please review, Carl Eugen
> >
> >>  utils.c |    4 +++-
> >>  1 file changed, 3 insertions(+), 1 deletion(-)
> >> 519f209901429efaf9dffec381290a6a83573deb
> >> 0001-lavf-utils-Do-not-overflow-in-update_initial_timesta.patch
> >> From 09a31f8f6584f0c97443fd6edc7fcf7142b6a6ff Mon Sep 17 00:00:00 2001
> >> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> >> Date: Sat, 24 Sep 2016 15:26:21 +0200
> >> Subject: [PATCH] lavf/utils: Do not overflow in
> >> update_initial_timestamps().
> >>
> >> Fixes ticket #5136.
> >> ---
> >>  libavformat/utils.c |    4 +++-
> >>  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > probably ok
> > it might be ultimately easier to reject demuxer output that has
> > timestamps close to INT64 MAX/MIN instead of protecting all
> > computations one by one though
> 
> I don't disagree but I am probably unable to improve the patch.
> Do you want me to apply?

ive posted an alternative

[...]
Carl Eugen Hoyos Sept. 26, 2016, 6:20 a.m. UTC | #4
2016-09-25 23:55 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:

>> > probably ok
>> > it might be ultimately easier to reject demuxer output that has
>> > timestamps close to INT64 MAX/MIN instead of protecting all
>> > computations one by one though
>>
>> I don't disagree but I am probably unable to improve the patch.
>> Do you want me to apply?
>
> ive posted an alternative

Looks much simpler, thank you!

Carl Eugen
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 93ea6ff..4362a12 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -1069,7 +1069,9 @@  static void update_initial_timestamps(AVFormatContext *s, int stream_index,
     if (st->first_dts != AV_NOPTS_VALUE ||
         dts           == AV_NOPTS_VALUE ||
         st->cur_dts   == AV_NOPTS_VALUE ||
-        is_relative(dts))
+        is_relative(dts) ||
+        INT64_MIN + RELATIVE_TS_BASE > st->cur_dts ||
+        (dts > 0 ? INT64_MAX - dts < st->cur_dts - RELATIVE_TS_BASE : INT64_MIN - dts > st->cur_dts - RELATIVE_TS_BASE))
         return;
 
     st->first_dts = dts - (st->cur_dts - RELATIVE_TS_BASE);