diff mbox

[FFmpeg-devel] avcodec/agm: Fix integer overflow with w/h

Message ID 20190404230847.18897-1-michael@niedermayer.cc
State Accepted
Commit 2169a3f262beedcb06fdb0e0e5277a680570df13
Headers show

Commit Message

Michael Niedermayer April 4, 2019, 11:08 p.m. UTC
Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
Fixes: 13999/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5644405991538688

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/agm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Paul B Mahol April 5, 2019, 7:54 a.m. UTC | #1
On 4/5/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to
> an unsigned type to negate this value to itself
> Fixes:
> 13999/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5644405991538688
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/agm.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/agm.c b/libavcodec/agm.c
> index 2d2092222d..cbd45e8095 100644
> --- a/libavcodec/agm.c
> +++ b/libavcodec/agm.c
> @@ -535,11 +535,13 @@ static int decode_frame(AVCodecContext *avctx, void
> *data,
>
>      s->flags = 0;
>      w = bytestream2_get_le32(gbyte);
> +    h = bytestream2_get_le32(gbyte);
> +    if (w == INT32_MIN || h == INT32_MIN)
> +        return AVERROR_INVALIDDATA;
>      if (w < 0) {
>          w = -w;
>          s->flags |= 2;
>      }
> -    h = bytestream2_get_le32(gbyte);
>      if (h < 0) {
>          h = -h;
>          s->flags |= 1;
> --

OK
Michael Niedermayer April 5, 2019, 10:51 a.m. UTC | #2
On Fri, Apr 05, 2019 at 09:54:51AM +0200, Paul B Mahol wrote:
> On 4/5/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > Fixes: negation of -2147483648 cannot be represented in type 'int'; cast to
> > an unsigned type to negate this value to itself
> > Fixes:
> > 13999/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AGM_fuzzer-5644405991538688
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/agm.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/agm.c b/libavcodec/agm.c
> > index 2d2092222d..cbd45e8095 100644
> > --- a/libavcodec/agm.c
> > +++ b/libavcodec/agm.c
> > @@ -535,11 +535,13 @@ static int decode_frame(AVCodecContext *avctx, void
> > *data,
> >
> >      s->flags = 0;
> >      w = bytestream2_get_le32(gbyte);
> > +    h = bytestream2_get_le32(gbyte);
> > +    if (w == INT32_MIN || h == INT32_MIN)
> > +        return AVERROR_INVALIDDATA;
> >      if (w < 0) {
> >          w = -w;
> >          s->flags |= 2;
> >      }
> > -    h = bytestream2_get_le32(gbyte);
> >      if (h < 0) {
> >          h = -h;
> >          s->flags |= 1;
> > --
> 
> OK

will apply

thanks

[...]
diff mbox

Patch

diff --git a/libavcodec/agm.c b/libavcodec/agm.c
index 2d2092222d..cbd45e8095 100644
--- a/libavcodec/agm.c
+++ b/libavcodec/agm.c
@@ -535,11 +535,13 @@  static int decode_frame(AVCodecContext *avctx, void *data,
 
     s->flags = 0;
     w = bytestream2_get_le32(gbyte);
+    h = bytestream2_get_le32(gbyte);
+    if (w == INT32_MIN || h == INT32_MIN)
+        return AVERROR_INVALIDDATA;
     if (w < 0) {
         w = -w;
         s->flags |= 2;
     }
-    h = bytestream2_get_le32(gbyte);
     if (h < 0) {
         h = -h;
         s->flags |= 1;