From patchwork Sun Apr 16 16:48:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41206 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1838813pzb; Sun, 16 Apr 2023 09:49:08 -0700 (PDT) X-Google-Smtp-Source: AKy350aA96lqKalAT/ETyFniL9VVnfiyIYbTjt9ImnzDmNSR9Fjboy0tWUlPOo6wkXDLTQbzMQ2C X-Received: by 2002:a17:906:12d8:b0:94d:20d2:47ce with SMTP id l24-20020a17090612d800b0094d20d247cemr5363805ejb.14.1681663748473; Sun, 16 Apr 2023 09:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681663748; cv=none; d=google.com; s=arc-20160816; b=CamjCdu+0AHS3HprTNbaoFrgmlVQj4r+Quh7v3xMIXf6n10zPUwz3UA9+mMhaEtvVT OeilMcwMn8t3f0vJ0fv21+LF2eQ/nTGgfYCtRt9UyJUtsHFFFx+0KQAA+DJi7OjQStCs FOPr/T9ZNteiCjvFYZsJia5TbNrvIPlLIf+RmYReSw71N2w7xIGK5hRwISg1eTkdGWY7 N8z8g/tjYz0GN0u7ejpiIkA/XXBMlVVvztjLXkeacZh5/Ym/ho5a9tAQWdTpGMULnuYF 4A4fEx1i4xI0+ZmQQxZuZ73YInQdAtkUErSa8i1esaJAk/vjFVbbu55dlbypQgXyp+zD MB5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=F9woYRcuOTJDmAuEb1y1xEpTd4eWJbywEIhMRF7mfHs=; b=AgnnAjJEnEzrtJ2ad5JhkC7izCFOnOcC2HbcvRuXx64PUROvW5rrDnzWLvFHHFQzKD r3iFUv/uqIT6qRnTfmQxBSoJ6/qkDylK5YbKLewpheohMd2YzclvslgOhRSfQU3bVyHo PTl8wGMVm6w+R2l9Lfwbm5ecd97lMFUt+ArexvCm1oKFkh59h88kjYkZs/UwYzr5nuK9 VD413cmwv20+BhvbqG+sjAlF2P+gHv84L6OTUtR0OtUvQgwST/h/CLr64RVRmRCzv3ZB tqxYv24n8T6ePqfRkON6A0fASgxWIh92wwCp1No5hY94qwddbjIgIc/vXSyKNk+/vmcX ST6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fv36-20020a17090750a400b0094f1fa2b276si659316ejc.650.2023.04.16.09.49.08; Sun, 16 Apr 2023 09:49:08 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 35B9368BDDD; Sun, 16 Apr 2023 19:48:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 792B968BCE9 for ; Sun, 16 Apr 2023 19:48:38 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 8100D100008 for ; Sun, 16 Apr 2023 16:48:37 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 16 Apr 2023 18:48:22 +0200 Message-Id: <20230416164830.15664-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230416164830.15664-1-michael@niedermayer.cc> References: <20230416164830.15664-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 03/11] avcodec/pngdec: Do not pass AVFrame into global header decode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: h7Fmti0Lwgzs The global header should not contain a frame, and decoding it would result in leaks Fixes: memleak Fixes: 45982/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APNG_fuzzer-6603443149340672 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/pngdec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 679cb8c2281..5dc36d400c2 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -734,6 +734,8 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, int ret; size_t byte_depth = s->bit_depth > 8 ? 2 : 1; + if (!p) + return AVERROR_INVALIDDATA; if (!(s->hdr_state & PNG_IHDR)) { av_log(avctx, AV_LOG_ERROR, "IDAT without IHDR\n"); return AVERROR_INVALIDDATA; @@ -1515,6 +1517,9 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, } exit_loop: + if (!p) + return AVERROR_INVALIDDATA; + if (avctx->codec_id == AV_CODEC_ID_PNG && avctx->skip_frame == AVDISCARD_ALL) { return 0; @@ -1727,7 +1732,7 @@ static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p, if ((ret = inflateReset(&s->zstream.zstream)) != Z_OK) return AVERROR_EXTERNAL; bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size); - if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0) + if ((ret = decode_frame_common(avctx, s, NULL, avpkt)) < 0) return ret; }