From patchwork Wed Oct 9 10:14:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 15631 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id DB77644921F for ; Wed, 9 Oct 2019 13:22:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4F476881BE; Wed, 9 Oct 2019 13:22:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-3.mx.upcmail.net (vie01a-dmta-pe05-3.mx.upcmail.net [84.116.36.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D42C687F26 for ; Wed, 9 Oct 2019 13:22:52 +0300 (EEST) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1iI91N-0006Vl-5z for ffmpeg-devel@ffmpeg.org; Wed, 09 Oct 2019 12:16:41 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id I90PifjmTwlysI90PiS55D; Wed, 09 Oct 2019 12:15:41 +0200 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=E5OzWpVl c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=nZOtpAppAAAA:20 a=J7Pasc7uSZboVEAN-6YA:9 a=6TD3J1PkD3VlBads:21 a=rRlrAdLBmHym9B5Z:21 a=1fhp2MxaeJtTNGEnv6mo:22 a=Z5ABNNGmrOfJ6cZ5bIyy:22 a=UDnyf2zBuKT2w-IlGP_r:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Wed, 9 Oct 2019 12:14:54 +0200 Message-Id: <20191009101454.1608-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009101454.1608-1-michael@niedermayer.cc> References: <20191009101454.1608-1-michael@niedermayer.cc> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfA6lTvGLXyRk0Ya1bZ6NwswbxyyqdQkmriJjr9tFNgtymW4HSCjHeytW3ary1FOKupWWRuSSlKDZopV+ndxXvSDm5hN965OkGgpg9iC+L5eSLj0H2uy+ ZZwAnl/Trgc3U/UWW7fA21Yq3fvM3F26/hSN7XwuUXcXOdVRq1kUpcIw Subject: [FFmpeg-devel] [PATCH 6/6] avcodec/wmaprodec: Fix cleanup on error X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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 }, };