diff mbox

[FFmpeg-devel] Avoid undefined behavior when start_time_text is -1<<63

Message ID CAEVbG5ofxot9AYnuXSmtU0dN59B87RPH88ga0ypk3FaiTMD4PA@mail.gmail.com
State New
Headers show

Commit Message

Fredrik Hubinette Aug. 20, 2018, 8:03 p.m. UTC
Ok, let's use cast, new patch attached.


On Mon, Jul 30, 2018 at 4:53 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Mon, Jul 30, 2018 at 01:49:24PM -0700, Fredrik Hubinette wrote:
> > Is casting a negative integer to unsigned defined behavior?
>
> yes
>
> 6.3.1.3 Signed and unsigned integers
>
> 2 Otherwise, if the new type is unsigned, the value is converted by
> repeatedly adding or
>   subtracting one more than the maximum value that can be represented in
> the new type
>   until the value is in the range of the new type.49)
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I do not agree with what you have to say, but I'll defend to the death your
> right to say it. -- Voltaire
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Comments

Michael Niedermayer Aug. 22, 2018, 12:34 a.m. UTC | #1
On Mon, Aug 20, 2018 at 01:03:31PM -0700, Fredrik Hubinette wrote:
> Ok, let's use cast, new patch attached.
> 
> 
> On Mon, Jul 30, 2018 at 4:53 PM Michael Niedermayer <michael@niedermayer.cc>
> wrote:
> 
> > On Mon, Jul 30, 2018 at 01:49:24PM -0700, Fredrik Hubinette wrote:
> > > Is casting a negative integer to unsigned defined behavior?
> >
> > yes
> >
> > 6.3.1.3 Signed and unsigned integers
> >
> > 2 Otherwise, if the new type is unsigned, the value is converted by
> > repeatedly adding or
> >   subtracting one more than the maximum value that can be represented in
> > the new type
> >   until the value is in the range of the new type.49)
> >
> > [...]
> > --
> > Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> >
> > I do not agree with what you have to say, but I'll defend to the death your
> > right to say it. -- Voltaire
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >

>  utils.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> bc4877b8167668c81cf978a7e3cecfc412ca8c92  0001-avoid-undefined-integer-overflow-behavior.patch
> From e8f3a5a4ff9b89b33f4067c7aa735fff9895333e Mon Sep 17 00:00:00 2001
> From: Fredrik Hubinette <hubbe@google.com>
> Date: Mon, 20 Aug 2018 12:59:32 -0700
> Subject: [PATCH] avoid undefined integer overflow behavior

will apply

thanks

[...]
diff mbox

Patch

From e8f3a5a4ff9b89b33f4067c7aa735fff9895333e Mon Sep 17 00:00:00 2001
From: Fredrik Hubinette <hubbe@google.com>
Date: Mon, 20 Aug 2018 12:59:32 -0700
Subject: [PATCH] avoid undefined integer overflow behavior

---
 libavformat/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index fcd4328587..b0b5e164a6 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2666,7 +2666,7 @@  static void update_stream_timings(AVFormatContext *ic)
                 duration = FFMAX(duration, duration1);
         }
     }
-    if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text < AV_TIME_BASE))
+    if (start_time == INT64_MAX || (start_time > start_time_text && start_time - (uint64_t)start_time_text < AV_TIME_BASE))
         start_time = start_time_text;
     else if (start_time > start_time_text)
         av_log(ic, AV_LOG_VERBOSE, "Ignoring outlier non primary stream starttime %f\n", start_time_text / (float)AV_TIME_BASE);
-- 
2.18.0.865.gffc8e1a3cd6-goog