From patchwork Sun Oct 3 13:36:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 30890 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6506:0:0:0:0:0 with SMTP id z6csp3433608iob; Sun, 3 Oct 2021 06:37:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWgobFX7YGSrqsG3hRvUWv8tT70/e2NKkOeP0P6tfDq5QJk2eaOBPdvX5hmF458queJIbU X-Received: by 2002:a50:9dc4:: with SMTP id l4mr11130290edk.208.1633268239718; Sun, 03 Oct 2021 06:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633268239; cv=none; d=google.com; s=arc-20160816; b=fZfEXpssRvR6U+ULy+VGLKyq8cx/oSyJZfRSjb2yl5qNyHJlXRteJGNrtcNJeQ0C1g Wr5sKVJLeJ+fZVJL3/PuOIvBCuyvVCx/rGH39A5VtKITkCf39wggo3cEObUjrfNjt8Px l52aZ293AUmteg0HqUCGY5KbMQiJIdSr2XwVTCNU0evnE9f9Sk1IFjb0l7tgCZyr5vhQ I2dlWkKC4w6efqidEOLx2A0bBhn8aHKqdcIBjKmr3ZsKQkjXYBN6Tp5wmlT47CO9Tr+U gUBZPTnVJ4EKolBXbnD/tnpBNUlPxtwOc1brQScUn8rGwOOo1CToDXwfqSZlaja51pz+ a1cQ== 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=6ghkGacy+f/KP1jFb/fYXRmUZW1pSA3M74hICP69yIw=; b=LY9hiFZIB7dS1g/UgAZrC252y2VOqhJTx6ktEGgFdtCgWzIFGEvraud1+NmuEsmqX4 0L/Gpm6KsSCjJr2IGjTUlVFb+Jo+9MCGTUpwuFF4XPRP07pDivxqMTBC9dhWyLCjGwh/ 8Wd+ifGZjQj/hXJbE+bS4CuLWBlpt57rkm7GskWgC9ubbxJafTyXnzwl+OKH/2fP3p0c QR1UaMR4h6TjLu9GPudgMyINhGasQ1ewdx1Rr0/s7j5RTzN5c+6F0f5lexKZ9P2Ws1lK NbV4bFWNnZmy0Qvmpewa2XNhRarLfL8P6wghb6qIlwwtnEO60AQ3Qv6N7EvnAfzbhibS Wm+Q== 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 c10si710973edj.210.2021.10.03.06.37.18; Sun, 03 Oct 2021 06:37:19 -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 43DB868A7C8; Sun, 3 Oct 2021 16:37:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-2.mx.upcmail.net (vie01a-dmta-pe05-2.mx.upcmail.net [84.116.36.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07C7868A58C for ; Sun, 3 Oct 2021 16:37:07 +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 1mX1fv-00A323-0D for ffmpeg-devel@ffmpeg.org; Sun, 03 Oct 2021 15:37:07 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id X1exmMhjUljeHX1exmMskK; Sun, 03 Oct 2021 15:36:07 +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=BoHjPrf5 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=yBkewQt_Hi6Bwk3NKFoA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 3 Oct 2021 15:36:06 +0200 Message-Id: <20211003133606.30712-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211003133606.30712-1-michael@niedermayer.cc> References: <20211003133606.30712-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfKMZqhLg1daDmAthNdfDk0I5c3vxFhYFDmgGMPHq8DyBoV06iGzwfj+jCAbc36LBdJoMy8fx8VANMuMkuk6MSNx3M8nUNndcDvGvIT4Yk5ABZFz9kfrx /TguDRnl0J4+l+9Bz3cxLbFz4F1wSt0OBJCV3tCGFmwVTAnFti8Wk2Pe Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/iff: limit written bytes to twice the output array size in decode_delta_l() 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: Tz3dTSo6VTC0 Fixes: Timeout Fixes: 39436/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_IFF_ILBM_fuzzer-6624915520880640 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/iff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/iff.c b/libavcodec/iff.c index 6a4c466b44f..1dcf0e00ed4 100644 --- a/libavcodec/iff.c +++ b/libavcodec/iff.c @@ -1456,6 +1456,7 @@ static void decode_delta_l(uint8_t *dst, int planepitch_byte = (w + 7) / 8; int planepitch = ((w + 15) / 16) * 2; int pitch = planepitch * bpp; + int count = 0; if (buf_end - buf <= 64) return; @@ -1487,6 +1488,8 @@ static void decode_delta_l(uint8_t *dst, int16_t cnt = bytestream2_get_be16(&ogb); uint16_t data; + if (count > dst_size) + break; offset = ((2 * offset) / planepitch_byte) * pitch + ((2 * offset) % planepitch_byte) + k * planepitch; if (cnt < 0) { if (bytestream2_get_bytes_left(&dgb) < 2) @@ -1494,6 +1497,7 @@ static void decode_delta_l(uint8_t *dst, bytestream2_seek_p(&pb, offset, SEEK_SET); cnt = -cnt; data = bytestream2_get_be16(&dgb); + count += cnt; for (i = 0; i < cnt; i++) { bytestream2_put_be16(&pb, data); bytestream2_skip_p(&pb, dstpitch - 2); @@ -1502,6 +1506,7 @@ static void decode_delta_l(uint8_t *dst, if (bytestream2_get_bytes_left(&dgb) < 2*cnt) break; bytestream2_seek_p(&pb, offset, SEEK_SET); + count += cnt; for (i = 0; i < cnt; i++) { data = bytestream2_get_be16(&dgb); bytestream2_put_be16(&pb, data);