From patchwork Sun Nov 28 18:55:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 31787 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp5138185iob; Sun, 28 Nov 2021 10:56:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxt/hMAOKoQnmG3+EbCbP5xWjg5GvaS/yf/sWnn+sMRGOOpIh8G1Q5xNaei1A6nNHm4D2Kl X-Received: by 2002:a17:907:3e22:: with SMTP id hp34mr54721934ejc.491.1638125788777; Sun, 28 Nov 2021 10:56:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638125788; cv=none; d=google.com; s=arc-20160816; b=yOWlYyIPsTyzlvU6qOBoYuFHBfXHsIO6QkFTA1rESZ1smB5FHOLDFUfiiYzo51n0F1 m7Sw6P/U/N3t59n6kUOnCSTjy7Dph36iRU4s2NKZt8EdyE4S0+XMI4EA2VPzbhrTlPpm R5+mUwl7gV45sjsT2c0Mg0GK+CxnkbMzFD2fD7C8GH5uyGnWjKC6QgqNSbV5+ycZkMi7 CeR5Pd22bfZQhX384g9WDjfditKxlhZHhp1GILsdpWPR+NoisVNNxk+tmRvSxGvdjizm boJO1mYFLQ9ycr+vRf9PZzsyHrf+6D9/7gW4qqLf80SaeHhtXvED95JL6Xbe7y4Oph+X YbJA== 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=g0SKTByfcoCnyR3dDrkVaJuaDpdoSrYJgKZ+2cVFdcg=; b=OuTA4/9MNFYwBHT+0f6ZoFO51oRJftI46Z2oDO6iFr85qwq/sEoTX2S1VubxT2qjV7 6I1Th1Cl0y9rrOiVzDmlvJlFbQAWQL9CAVJkCwpgZdvsSdR9A36MfLpzNScsd3Fzkd4H etDonVib4I/OJH5t6qsco2+M8S/ViGN56Vg3c1JnhgKvHO175POiW6Lx9ZnDj9/IvS/e UaVZ3C0ebruR1cFTo4mVGPL3DhKoJnvWWKHTaRE4HoMhPjbzPlb09CheGrSzEn/Vhu6y gDqJxswIBiMNdV5mvtCK48HIyT8/tZMag8csYlEKc6rAfvq0KU7Ccl8tcmiaCUf8ChIt g45Q== 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 y1si26254215eda.530.2021.11.28.10.56.27; Sun, 28 Nov 2021 10:56:28 -0800 (PST) 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 AAA4968A583; Sun, 28 Nov 2021 20:56:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe04-2.mx.upcmail.net (unknown [62.179.121.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D305C68A0E7 for ; Sun, 28 Nov 2021 20:56:15 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe04.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1mrPLT-001fq7-0K for ffmpeg-devel@ffmpeg.org; Sun, 28 Nov 2021 19:56:15 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id rPKVm8lUuSgGFrPKVm4riO; Sun, 28 Nov 2021 19:55:15 +0100 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=f8Q2+96M c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=NEAV23lmAAAA:8 a=SfVjgJAXzBoTzeKltYYA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 28 Nov 2021 19:55:14 +0100 Message-Id: <20211128185514.19253-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211128185514.19253-1-michael@niedermayer.cc> References: <20211128185514.19253-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfCVkAf9RKtChImErsLyFXbCGLC3PNbVlYFBqnvlUPpaPwztw4SLNQpNo7wM7hAXeNlVFf2TLNEvkSRI34GTzgYqwNv3kwSGY2CApeKCHRhHQFNGmxsOm 7p56Utme6WBrBDeSAe2OPWFc++Pkt8SgNYoj9YCBRjNGTvkcRvttOxIL Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/gemdec: Check tag & planes before image allocation 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: tuQNfwKAazm8 Fixes: Timeout Fixes: 41083/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_GEM_fuzzer-5843826518917120 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/gemdec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/gemdec.c b/libavcodec/gemdec.c index 2464dda8a7e..eee21a50d4b 100644 --- a/libavcodec/gemdec.c +++ b/libavcodec/gemdec.c @@ -157,6 +157,14 @@ static int gem_decode_frame(AVCodecContext *avctx, if (header_size >= 11) tag = bytestream2_peek_be32(&gb); + if (tag == AV_RB32("STTT") || tag == AV_RB32("TIMG") || tag == AV_RB32("XIMG") || + planes == 1 || planes == 2 || planes == 3 || planes == 4 || + planes == 8 || planes == 16 || planes == 24) { + } else { + avpriv_request_sample(avctx, "planes=%d", planes); + return AVERROR_PATCHWELCOME; + } + if ((ret = ff_get_buffer(avctx, p, 0)) < 0) return ret; @@ -236,9 +244,6 @@ static int gem_decode_frame(AVCodecContext *avctx, planes = 1; row_width = avctx->width * pixel_size; put_lines = put_lines_bytes; - } else { - avpriv_request_sample(avctx, "planes=%d", planes); - return AVERROR_PATCHWELCOME; } ret = av_reallocp_array(&avctx->priv_data, planes, row_width);