Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 2/3] avcodec/osq: avoid several signed integer overflows
Date: Tue, 26 Dec 2023 13:56:31 -0300
Message-ID: <e6710561-1222-49c6-bb9f-5dc91d2187e1@gmail.com> (raw)
In-Reply-To: <20231226163731.4147-2-michael@niedermayer.cc>

On 12/26/2023 1:37 PM, Michael Niedermayer wrote:
> Fixes: signed integer overflow: 178459578 + 2009763270 cannot be represented in type 'int'
> Fixes: 62285/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_OSQ_fuzzer-5013423686287360
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   libavcodec/osq.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/osq.c b/libavcodec/osq.c
> index abe15c97f18..f2771c46eb5 100644
> --- a/libavcodec/osq.c
> +++ b/libavcodec/osq.c
> @@ -222,8 +222,8 @@ static int osq_channel_parameters(AVCodecContext *avctx, int ch)
>   #define C (-3)
>   #define D (-4)
>   #define E (-5)
> -#define P2 ((dst[A] + dst[A]) - dst[B])
> -#define P3 ((dst[A] - dst[B]) * 3 + dst[C])
> +#define P2 (((unsigned)dst[A] + dst[A]) - dst[B])
> +#define P3 (((unsigned)dst[A] - dst[B]) * 3 + dst[C])
>   
>   static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int downsample)
>   {
> @@ -273,10 +273,10 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int
>               case 0:
>                   break;
>               case 1:
> -                dst[n] += dst[A];
> +                dst[n] += (unsigned)dst[A];
>                   break;
>               case 2:
> -                dst[n] += dst[A] + p;
> +                dst[n] += (unsigned)dst[A] + p;
>                   break;
>               case 3:
>                   dst[n] += P2;
> @@ -291,28 +291,28 @@ static int do_decode(AVCodecContext *avctx, AVFrame *frame, int decorrelate, int
>                   dst[n] += P3 + p;
>                   break;
>               case 7:
> -                dst[n] += (P2 + P3) / 2 + p;
> +                dst[n] += (int)(P2 + P3) / 2 + (unsigned)p;

Would 2U work for this? It's shorted and more readable that casts 
everywhere. Same for most cases below.

>                   break;
>               case 8:
> -                dst[n] += (P2 + P3) / 2;
> +                dst[n] += (int)(P2 + P3) / 2;
>                   break;
>               case 9:
> -                dst[n] += (P2 * 2 + P3) / 3 + p;
> +                dst[n] += (int)(P2 * 2 + P3) / 3 + (unsigned)p;
>                   break;
>               case 10:
> -                dst[n] += (P2 + P3 * 2) / 3 + p;
> +                dst[n] += (int)(P2 + P3 * 2) / 3 + (unsigned)p;
>                   break;
>               case 11:
> -                dst[n] += (dst[A] + dst[B]) / 2;
> +                dst[n] += (int)((unsigned)dst[A] + dst[B]) / 2;
>                   break;
>               case 12:
> -                dst[n] += dst[B];
> +                dst[n] += (unsigned)dst[B];
>                   break;
>               case 13:
> -                dst[n] += (dst[D] + dst[B]) / 2;
> +                dst[n] += (int)(unsigned)(dst[D] + dst[B]) / 2;
>                   break;
>               case 14:
> -                dst[n] += (P2 + dst[A]) / 2 + p;
> +                dst[n] += (int)((unsigned)P2 + dst[A]) / 2 + (unsigned)p;
>                   break;
>               default:
>                   return AVERROR_INVALIDDATA;
_______________________________________________
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".

  reply	other threads:[~2023-12-26 16:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-26 16:37 [FFmpeg-devel] [PATCH 1/3] avcodec/osq: Implement flush() Michael Niedermayer
2023-12-26 16:37 ` [FFmpeg-devel] [PATCH 2/3] avcodec/osq: avoid several signed integer overflows Michael Niedermayer
2023-12-26 16:56   ` James Almer [this message]
2023-12-28 19:53     ` Michael Niedermayer
2024-03-26  0:16   ` Michael Niedermayer
2023-12-26 16:37 ` [FFmpeg-devel] [PATCH 3/3] avformat/concatdec: clip outpoint - inpoint overflow in get_best_effort_duration() Michael Niedermayer
2023-12-26 19:09 ` [FFmpeg-devel] [PATCH 1/3] avcodec/osq: Implement flush() Andreas Rheinhardt
2023-12-28 19:48   ` Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6710561-1222-49c6-bb9f-5dc91d2187e1@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git