From patchwork Sun Sep 10 19:10:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 5076 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp2289259jaa; Sun, 10 Sep 2017 12:10:55 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAdO1v56TmHOuaSPlS+2xBqFday9i2lzQGAWel3iQsUh2yz5udggAldthdSL9NvNpjpO5fa X-Received: by 10.28.97.135 with SMTP id v129mr6694041wmb.98.1505070655085; Sun, 10 Sep 2017 12:10:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505070655; cv=none; d=google.com; s=arc-20160816; b=NOHc1N2QtEvFY/K9yNGayghE4Ae5rKSOjzeaIYIN+29OcjGdv13S+72vLSWRX0HyjE 4lMXCNBfcY+qiZxWdp6AsNN00ThZD+so3TbbZXjQAp5sxB52zahsrNSGSxmtg0/9V+tO KhduFLm1S4Rn67HHuJewMGUyU8vF1KycDdVlTMUhWt3eAVCABBbaCE+E08P1Ky0/r+HB mIjBbJCmD/61n+ah4aMmf7mL5H6XWYiY+cpbyfGlYv48p6OXIbR1gAVN23ssrF72+mtz P5QctgXCx4lISZ4ONRldpd+FHLkM6+XvKQ2x6g95Ro3BwxJ1Gzz7xuLAUCGCSeNuKnJO nzEw== 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=rXqqyQjCddE66BeLab+CKyDDC54SSDJyfD6Ns80o/5c=; b=OOL+hh575DPuL2buBekcNT19Frv/XubqC2QvP2k/jBF0v9PkFykyikIyjFe9l4Gq91 BD7rbypDmfquDufxnI7Hq4ScXnJFhtUMxpqJjZOdKnPRaBEKvZILxBmwmT9ehp61fG3r j+d4y8tT+QUThVCGkXAfUIFj0qWArKsjH13QEwEzqc5zxEwgJecfTE5KBJ9DsQ8yfuZp xMw8hsXJVToJMNdIjsIr8HYSGBDFhfxz3y+K6XXKGoLjkDrby0Fpkg2cxXtOugW77KMK kY5ept4+4X1DSRDkPV3U5jOO89OXP+3gz3uP/hZqjeNJeYaWt8e6dGugo3PlHd+EQqay SANA== 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 w96si5527396wrc.79.2017.09.10.12.10.54; Sun, 10 Sep 2017 12:10:55 -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 3B3126899CE; Sun, 10 Sep 2017 22:10:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe08-2.mx.upcmail.net (vie01a-dmta-pe08-2.mx.upcmail.net [84.116.36.21]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C059A680486 for ; Sun, 10 Sep 2017 22:10:40 +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 1dr7cz-0002yJ-G2 for ffmpeg-devel@ffmpeg.org; Sun, 10 Sep 2017 21:10:45 +0200 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id 7vAK1w00G0S5wYM01vALuk; Sun, 10 Sep 2017 21:10:20 +0200 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 10 Sep 2017 21:10:16 +0200 Message-Id: <20170910191018.3390-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.14.1 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/shorten: Move buffer allocation and offset init to end of read_header() 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" They are time consuming operations, performing them after the other checks improves the speed with damaged input dramatically. Fixes: Timeout Fixes: 2928/clusterfuzz-testcase-4992812120539136 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/shorten.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 18b77300a0..49af6beec6 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -462,12 +462,6 @@ static int read_header(ShortenContext *s) } s->nwrap = FFMAX(NWRAP, maxnlpc); - if ((ret = allocate_buffers(s)) < 0) - return ret; - - if ((ret = init_offset(s)) < 0) - return ret; - if (s->version > 1) s->lpcqoffset = V2LPCQOFFSET; @@ -504,6 +498,13 @@ static int read_header(ShortenContext *s) } end: + + if ((ret = allocate_buffers(s)) < 0) + return ret; + + if ((ret = init_offset(s)) < 0) + return ret; + s->cur_chan = 0; s->bitshift = 0;