diff mbox

[FFmpeg-devel,6/6] avcodec/wmaprodec: Fix cleanup on error

Message ID 20191009101454.1608-6-michael@niedermayer.cc
State Accepted
Commit a5d29812ec364ad4b83b5c2dba281f1b559a518b
Headers show

Commit Message

Michael Niedermayer Oct. 9, 2019, 10:14 a.m. UTC
Fixes: memleaks
Fixes: 18023/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_XMA2_fuzzer-5642535011090432

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

Comments

Paul B Mahol Oct. 9, 2019, 10:29 a.m. UTC | #1
probably ok

On 10/9/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: memleaks
> Fixes:
> 18023/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_XMA2_fuzzer-5642535011090432
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/wmaprodec.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
> index 6ce2dd4adb..5c18479b3b 100644
> --- a/libavcodec/wmaprodec.c
> +++ b/libavcodec/wmaprodec.c
> @@ -1888,12 +1888,14 @@ static av_cold int xma_decode_init(AVCodecContext
> *avctx)
>          s->num_streams = avctx->extradata[1];
>          if (avctx->extradata_size != (32 + ((avctx->extradata[0]==3)?0:8) +
> 4*s->num_streams)) {
>              av_log(avctx, AV_LOG_ERROR, "Incorrect XMA2 extradata size\n");
> +            s->num_streams = 0;
>              return AVERROR(EINVAL);
>          }
>      } else if (avctx->codec_id == AV_CODEC_ID_XMA1 && avctx->extradata_size
>>= 4) { /* XMAWAVEFORMAT */
>          s->num_streams = avctx->extradata[4];
>          if (avctx->extradata_size != (8 + 20*s->num_streams)) {
>              av_log(avctx, AV_LOG_ERROR, "Incorrect XMA1 extradata size\n");
> +            s->num_streams = 0;
>              return AVERROR(EINVAL);
>          }
>      } else {
> @@ -1906,6 +1908,7 @@ static av_cold int xma_decode_init(AVCodecContext
> *avctx)
>          s->num_streams <= 0
>      ) {
>          avpriv_request_sample(avctx, "More than %d channels in %d streams",
> XMA_MAX_CHANNELS, s->num_streams);
> +        s->num_streams = 0;
>          return AVERROR_PATCHWELCOME;
>      }
>
> @@ -1938,6 +1941,7 @@ static av_cold int xma_decode_end(AVCodecContext
> *avctx)
>          decode_end(&s->xma[i]);
>          av_frame_free(&s->frames[i]);
>      }
> +    s->num_streams = 0;
>
>      return 0;
>  }
> @@ -1993,6 +1997,7 @@ AVCodec ff_wmapro_decoder = {
>      .close          = wmapro_decode_end,
>      .decode         = wmapro_decode_packet,
>      .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
> +    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
>      .flush          = wmapro_flush,
>      .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
>                                                        AV_SAMPLE_FMT_NONE },
> @@ -2008,6 +2013,7 @@ AVCodec ff_xma1_decoder = {
>      .close          = xma_decode_end,
>      .decode         = xma_decode_packet,
>      .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 |
> AV_CODEC_CAP_DELAY,
> +    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
>      .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
>                                                        AV_SAMPLE_FMT_NONE },
>  };
> @@ -2023,6 +2029,7 @@ AVCodec ff_xma2_decoder = {
>      .decode         = xma_decode_packet,
>      .flush          = xma_flush,
>      .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 |
> AV_CODEC_CAP_DELAY,
> +    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
>      .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
>                                                        AV_SAMPLE_FMT_NONE },
>  };
> --
> 2.23.0
>
> _______________________________________________
> 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 Oct. 10, 2019, 11:54 a.m. UTC | #2
On Wed, Oct 09, 2019 at 12:29:33PM +0200, Paul B Mahol wrote:
> probably ok

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c
index 6ce2dd4adb..5c18479b3b 100644
--- a/libavcodec/wmaprodec.c
+++ b/libavcodec/wmaprodec.c
@@ -1888,12 +1888,14 @@  static av_cold int xma_decode_init(AVCodecContext *avctx)
         s->num_streams = avctx->extradata[1];
         if (avctx->extradata_size != (32 + ((avctx->extradata[0]==3)?0:8) + 4*s->num_streams)) {
             av_log(avctx, AV_LOG_ERROR, "Incorrect XMA2 extradata size\n");
+            s->num_streams = 0;
             return AVERROR(EINVAL);
         }
     } else if (avctx->codec_id == AV_CODEC_ID_XMA1 && avctx->extradata_size >= 4) { /* XMAWAVEFORMAT */
         s->num_streams = avctx->extradata[4];
         if (avctx->extradata_size != (8 + 20*s->num_streams)) {
             av_log(avctx, AV_LOG_ERROR, "Incorrect XMA1 extradata size\n");
+            s->num_streams = 0;
             return AVERROR(EINVAL);
         }
     } else {
@@ -1906,6 +1908,7 @@  static av_cold int xma_decode_init(AVCodecContext *avctx)
         s->num_streams <= 0
     ) {
         avpriv_request_sample(avctx, "More than %d channels in %d streams", XMA_MAX_CHANNELS, s->num_streams);
+        s->num_streams = 0;
         return AVERROR_PATCHWELCOME;
     }
 
@@ -1938,6 +1941,7 @@  static av_cold int xma_decode_end(AVCodecContext *avctx)
         decode_end(&s->xma[i]);
         av_frame_free(&s->frames[i]);
     }
+    s->num_streams = 0;
 
     return 0;
 }
@@ -1993,6 +1997,7 @@  AVCodec ff_wmapro_decoder = {
     .close          = wmapro_decode_end,
     .decode         = wmapro_decode_packet,
     .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .flush          = wmapro_flush,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
@@ -2008,6 +2013,7 @@  AVCodec ff_xma1_decoder = {
     .close          = xma_decode_end,
     .decode         = xma_decode_packet,
     .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
 };
@@ -2023,6 +2029,7 @@  AVCodec ff_xma2_decoder = {
     .decode         = xma_decode_packet,
     .flush          = xma_flush,
     .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
     .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
                                                       AV_SAMPLE_FMT_NONE },
 };