diff mbox series

[FFmpeg-devel,3/4] avformat/avidec: Avoid integer overflow in NI switch check

Message ID 20200215225105.12141-3-michael@niedermayer.cc
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avfilter/vf_aspect: Fix integer overflow in compute_dar()
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Michael Niedermayer Feb. 15, 2020, 10:51 p.m. UTC
Fixes: signed integer overflow: 0 - -9223372036854775808 cannot be represented in type 'long'
Fixes: Ticket8149

Found-by: Suhwan
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/avidec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Paul B Mahol Feb. 16, 2020, 11:25 a.m. UTC | #1
probably ok

On 2/15/20, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: signed integer overflow: 0 - -9223372036854775808 cannot be
> represented in type 'long'
> Fixes: Ticket8149
>
> Found-by: Suhwan
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/avidec.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> index ae0c227bb9..412e4a8479 100644
> --- a/libavformat/avidec.c
> +++ b/libavformat/avidec.c
> @@ -1532,11 +1532,12 @@ resync:
>          if (!avi->non_interleaved && st->nb_index_entries>1 &&
> avi->index_loaded>1) {
>              int64_t dts= av_rescale_q(pkt->dts, st->time_base,
> AV_TIME_BASE_Q);
>
> -            if (avi->dts_max - dts > 2*AV_TIME_BASE) {
> +            if (avi->dts_max < dts) {
> +                avi->dts_max = dts;
> +            } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
>                  avi->non_interleaved= 1;
>                  av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor
> interleaving\n");
> -            }else if (avi->dts_max < dts)
> -                avi->dts_max = dts;
> +            }
>          }
>
>          return 0;
> --
> 2.17.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Feb. 16, 2020, 2:47 p.m. UTC | #2
On Sun, Feb 16, 2020 at 12:25:07PM +0100, Paul B Mahol wrote:
> probably ok

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index ae0c227bb9..412e4a8479 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -1532,11 +1532,12 @@  resync:
         if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) {
             int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
 
-            if (avi->dts_max - dts > 2*AV_TIME_BASE) {
+            if (avi->dts_max < dts) {
+                avi->dts_max = dts;
+            } else if (avi->dts_max - (uint64_t)dts > 2*AV_TIME_BASE) {
                 avi->non_interleaved= 1;
                 av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n");
-            }else if (avi->dts_max < dts)
-                avi->dts_max = dts;
+            }
         }
 
         return 0;