From patchwork Sun Sep 5 19:24:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 30008 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp3153336iov; Sun, 5 Sep 2021 12:25:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTxneudbY4U+iHdT51Nxo/zkBAdWyWll0e4XpLgITexFiGK48OOvh6lGh12TYBi9PJ1Tvm X-Received: by 2002:a17:907:3f91:: with SMTP id hr17mr9986468ejc.496.1630869950226; Sun, 05 Sep 2021 12:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630869950; cv=none; d=google.com; s=arc-20160816; b=HJ8iH4lbE+0N8MaUbglX+oRgCJCnsH8HTrNN+6nolxTi7e3RDwLys/65XkYqeboiNP Je7Zl37lKtGtpv2tE9KJPJwcaJUvdY62vVwWH1huJsbqpwPyJz2V+WgUMPbQJkRGqPuI Etd3lXbDT+E026k/FOqUTXvXc96dQXhS2ZKRx8JcboXQD7PPuBvFSilRea+u+OOXQ2sn o3Gu8RR/Y/WpCgZTpkDVfGfZty394GcId7GmiphbyTbV0cClAAPGun3flSuzJIayxEOw sLgcMEDi2sQ8XStjSp/sRNZi5nbuzHrCSPSsEMJE3MBuhtdDM74W3rPmr727CaNwWjlT tfCg== 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=T7PnOW7bKpz8dsA043wt5uF6UiFkBM++vSh7aB1cR5k=; b=tbu3pCykmM6l16lwBGlwavH6DWpPXiGYPUkuuzNPK8WGbVKFc/HBOJR+uOxynDyYf/ 91kKaPSsMwAJusT1UlZ0IIDS74tkdZeehwQlz5WNcH4PS8Ej+1Jk4huFg92KshHa/iXg mBzs2+oHLZT5AT/pIvfvdSiwNphKnpHLlhw8nSlw0ZSIz5cOZa9e+Hu0slZh3QkxcCXk pUud6u1FsiCZLC37TdLa/p79TTXjvSSIpea9VIbEEmiRRCecChMt9BWDL7TYUJS4HXOb k4QjoSyxvrKXcGME8QYTXZydFJx0RVdeDB3y2hkDikgSUqZYXda4MmZVqtRNPhY6OFKJ +TNw== 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 h16si5987948edz.437.2021.09.05.12.25.49; Sun, 05 Sep 2021 12:25:50 -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 6AE9768A637; Sun, 5 Sep 2021 22:25:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe05-1.mx.upcmail.net [84.116.36.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 75EB368998C for ; Sun, 5 Sep 2021 22:25:19 +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 1mMxlX-00CYd8-8H for ffmpeg-devel@ffmpeg.org; Sun, 05 Sep 2021 21:25:19 +0200 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id MxkYmmGKfljeHMxkZmkPGE; Sun, 05 Sep 2021 21:24:19 +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=nZOtpAppAAAA:20 a=tsPA6si9V2nU2mv4JUUA:9 a=1fhp2MxaeJtTNGEnv6mo:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 5 Sep 2021 21:24:18 +0200 Message-Id: <20210905192418.25970-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210905192418.25970-1-michael@niedermayer.cc> References: <20210905192418.25970-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBUrUFtFewveXurTMd+9z/U8rFCInWG36VH9qzqQEiiwD8E0KFMeKd1QK8XW20SNvRFCm8Yf6Gmrq6qYojF8FOZKEHeUYOe9ngdXQnjI9xBF3vuDKt1L ABZEOwWVJ6GGSOFmU8o/AgjGrEw+2uo1PHDQyzVX+QqaZzhz9+C0kB+z Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/jpeg2000dec: Check that atom header is within bytsetream 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: aD1QC0rjs+6M Fixes: Infinite loop Fixes: 36666/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5912760671141888 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/jpeg2000dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index e62f7b19e6..c95f22bc90 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -2360,6 +2360,8 @@ static int jp2_find_codestream(Jpeg2000DecoderContext *s) atom_size >= 16) { uint32_t atom2_size, atom2, atom2_end; do { + if (bytestream2_get_bytes_left(&s->g) < 8) + break; atom2_size = bytestream2_get_be32u(&s->g); atom2 = bytestream2_get_be32u(&s->g); atom2_end = bytestream2_tell(&s->g) + atom2_size - 8;