From patchwork Mon Jul 2 18:45:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 9573 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp286196jad; Mon, 2 Jul 2018 11:46:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpevuURcykq+JZ3GUk+0B6VR+ahqZXsMgb3KJzeZlljIJaafI2rlhItz73Ex4XkqO2FDBNlY X-Received: by 2002:a1c:2bc1:: with SMTP id r184-v6mr8564567wmr.13.1530557201165; Mon, 02 Jul 2018 11:46:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530557201; cv=none; d=google.com; s=arc-20160816; b=NjYwpWpOAOkmC8EnUm72Cl4Knz/th3FMIBMBtefQ9N7ijOJV43NDCfVEJc4tvZRdeE J5ThHnK3cGg/qK91WhGMBiwfEXBOwPA2YVpFw9z6OUaXRRul5JTBw8HKv520aBcuydqT +9OERVfLsJf/syZKpweH+pZoAVpVwb2jAs+wKG+on8GZu3qfJ7XqZP/oF9o5W2IQSkNg DNkYS1+1sRK8dtEY0m9I9ja9SBfJphQqOLSq5eG1ihmEuJERygOBXy6nnG0a3RdoINYH ycF57ao0d0AmdcK3mCIxh1R99apA+beUt5KkuylBwo+A2AVzVT4IOKTp1RqqpFDB7aXc bNgw== 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:message-id:date:to:from:delivered-to :arc-authentication-results; bh=qTHutFQUhCtlfRrHzGEnfPR2FtfyOrDaL5PTC0vVCWs=; b=L9iqLDvcStxquBGj6X3m+hud7Ue0QpqIZrl1SIUHEkkS0C3xnvoKAgYhjrK5OYNGE5 gOZeMWqRfJKkrKX/hqP+v94vHZuWoi9lW7ibLubMMbbRongeaA9Cs60q3r2BJm6Y3ouJ 1DbTjqan4UeIArcsXh09pNwQm+N/+o2+L3l4vFPQIGhFQ7b5kkzrF/4LAYSqY6SwD6ew mbmwVtqn6Xgw5jCOzSW+prteYxi+apTOy+jvPWCEDiz8pW00HANPW8+tsgwCwgyae+0t eDGtbFhnELw/Lbk4qUl+iV+Gn2ail6lRazO/E2psFTi/baR8Q0OOfteyZdGj3/uII6wP zwuA== 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 65-v6si3027348wmm.160.2018.07.02.11.46.40; Mon, 02 Jul 2018 11:46:41 -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 4FDEB68A599; Mon, 2 Jul 2018 21:46:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe08-3.mx.upcmail.net (vie01a-dmta-pe08-3.mx.upcmail.net [84.116.36.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DDB6F68A576 for ; Mon, 2 Jul 2018 21:46:06 +0300 (EEST) Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe08.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1fa3py-0008TJ-BC for ffmpeg-devel@ffmpeg.org; Mon, 02 Jul 2018 20:46:10 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 5um01y01z0S5wYM01um1dF; Mon, 02 Jul 2018 20:46:02 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Mon, 2 Jul 2018 20:45:08 +0200 Message-Id: <20180702184511.12534-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.18.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/jpeg2000dec: Check that there are enough bytes for all tiles 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes: OOM Fixes: 8781/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5810709081358336 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/jpeg2000dec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c index 66f11bb2b2..4071b5ce53 100644 --- a/libavcodec/jpeg2000dec.c +++ b/libavcodec/jpeg2000dec.c @@ -343,7 +343,10 @@ static int get_siz(Jpeg2000DecoderContext *s) s->numXtiles = ff_jpeg2000_ceildiv(s->width - s->tile_offset_x, s->tile_width); s->numYtiles = ff_jpeg2000_ceildiv(s->height - s->tile_offset_y, s->tile_height); - if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(*s->tile)) { + // There must be at least a SOT and SOD per tile, their minimum size is 14 + if (s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(*s->tile) || + s->numXtiles * s->numYtiles * 14LL > bytestream2_size(&s->g) + ) { s->numXtiles = s->numYtiles = 0; return AVERROR(EINVAL); }