From patchwork Thu Nov 30 22:58:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 6479 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp451212jah; Thu, 30 Nov 2017 14:58:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMbRE5NE80eHnxlF5EdGFl99QCrPnHuvcc+DZ9p+JAsHaqsMrPEcDdB6DvA04F8OWi5oQLtU X-Received: by 10.28.33.66 with SMTP id h63mr890580wmh.152.1512082722975; Thu, 30 Nov 2017 14:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512082722; cv=none; d=google.com; s=arc-20160816; b=tB2foVrOJrcJsrvPFcgbgi+gvHb/nBwRfk8h/W2WrK8AaZxstV2xSTV3jmuK34CndL d+yvPxdY1NMcncRoL2SVDwsdY/NvOHfg8a/Zqs2JtAw5Q3zmGBNoTEzws387rYbyR7Mz nCfIBcHOxADq4qKcJlS8xlxwoGWOni+ywWaC4z5sjrZ6do+FwGMzzhw+/Cta46AZ7kci B//X1CJLo3mt/c2Q9RP+sXj9VSFTa36mPyKuI635eK1wZy63xj9p5IJlaqdWRigYFKBV xbQwhzzMArU3xxlIpM3Aa4qN451yfbVBA0D0gibBLcB8huK7L+n0KiNZPWJFwNGuSqZq +f7g== 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:arc-authentication-results; bh=xv516zeqeQ8ariiAoWq1wGumcr3sTuMfsQP1ciGiw9c=; b=K7gmVi7BNBWRCrO2kmncle0fNFyLV47ss/mN/v3mXsuw4EKvrwCP7KrdwnDTF+oa8h qEQIx75fE/xeeY7XdNZyQ2ofXusz1p6y5UID9fjWRe4o/asaEdqMKnqIUaASftF/qLm0 ZcEhD57cGQInh26+bUffc61WH+TBkgKRuF1kii/ZAY3qYEzk0WqAIKo4RRp9JjO/6HA2 2wlcxkXTlO8Lf+UuKnzYuWM9tdZB/UZpdkAP9fb2Vd96khKZeDrQ58ZmsaCJuuxNYM6a x9YpznHl7fAmuXDE8DuceXZT87jQhp5Vu9jq9j7grD8cYD36BMSLtl1AMM+xnz6X1Eme NT2Q== 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 d2si4121816wrf.65.2017.11.30.14.58.42; Thu, 30 Nov 2017 14:58:42 -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 B441B68A3C8; Fri, 1 Dec 2017 00:58:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-2.mx.upcmail.net (vie01a-qmta-pe02-2.mx.upcmail.net [62.179.121.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BE71A68A3AB for ; Fri, 1 Dec 2017 00:58:21 +0200 (EET) Received: from [172.31.218.36] (helo=vie01a-dmta-pe02-3.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1eKXmj-0001ex-2x for ffmpeg-devel@ffmpeg.org; Thu, 30 Nov 2017 23:58:25 +0100 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1eKXmd-0007A8-C6 for ffmpeg-devel@ffmpeg.org; Thu, 30 Nov 2017 23:58:19 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id gNyF1w00A0S5wYM01NyGR9; Thu, 30 Nov 2017 23:58:16 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 30 Nov 2017 23:58:11 +0100 Message-Id: <20171130225811.13103-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130225811.13103-1-michael@niedermayer.cc> References: <20171130225811.13103-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/jpeg2000: Only allocate Jpeg2000Pass for the encoder 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" Reduces memory needed. Fixes: OOM Fixes: 4427/clusterfuzz-testcase-minimized-5106919271301120 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/j2kenc.c | 4 +++- libavcodec/jpeg2000.c | 1 + libavcodec/jpeg2000.h | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c index 78ec88a694..3e542af3c6 100644 --- a/libavcodec/j2kenc.c +++ b/libavcodec/j2kenc.c @@ -941,7 +941,9 @@ static int encode_tile(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile, int tileno } if (!prec->cblk[cblkno].data) prec->cblk[cblkno].data = av_malloc(1 + 8192); - if (!prec->cblk[cblkno].data) + if (!prec->cblk[cblkno].passes) + prec->cblk[cblkno].passes = av_malloc_array(JPEG2000_MAX_PASSES, sizeof (*prec->cblk[cblkno].passes)); + if (!prec->cblk[cblkno].data || !prec->cblk[cblkno].passes) return AVERROR(ENOMEM); encode_cblk(s, &t1, prec->cblk + cblkno, tile, xx1 - xx0, yy1 - yy0, bandpos, codsty->nreslevels - reslevelno - 1); diff --git a/libavcodec/jpeg2000.c b/libavcodec/jpeg2000.c index 8551cf8d6c..5f3965047f 100644 --- a/libavcodec/jpeg2000.c +++ b/libavcodec/jpeg2000.c @@ -606,6 +606,7 @@ void ff_jpeg2000_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty) for (cblkno = 0; cblkno < nb_code_blocks; cblkno ++) { Jpeg2000Cblk *cblk = &prec->cblk[cblkno]; av_freep(&cblk->data); + av_freep(&cblk->passes); } av_freep(&prec->cblk); } diff --git a/libavcodec/jpeg2000.h b/libavcodec/jpeg2000.h index eaf7faf342..752feae96b 100644 --- a/libavcodec/jpeg2000.h +++ b/libavcodec/jpeg2000.h @@ -173,7 +173,7 @@ typedef struct Jpeg2000Cblk { int nb_terminations; int nb_terminationsinc; int data_start[JPEG2000_MAX_PASSES]; - Jpeg2000Pass passes[JPEG2000_MAX_PASSES]; + Jpeg2000Pass *passes; int coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}} } Jpeg2000Cblk; // code block