From patchwork Sat Dec 4 21:32:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 31971 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2480098iog; Sat, 4 Dec 2021 13:34:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJwt87olyRDQ5JxUQuRFwJaq667HE7MD7uNJu2n3ptY8ta98FtoZNELuXVzAsU6YHNeb87+m X-Received: by 2002:a17:907:8a12:: with SMTP id sc18mr34395956ejc.274.1638653668272; Sat, 04 Dec 2021 13:34:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638653668; cv=none; d=google.com; s=arc-20160816; b=AmU98qE30JQVFvp0B7kC27ra9R7kQd+PRkA+7B8JyHBCP/udcO9TfoGZhFjg28jBhV QnclRonDQzNRlxRWMUgW5hyXoFdHFBVFxvqMhkRa2HiC8UAeB2t8NvXSJe2uDjINY//y w2OF205pNJq5tpFGRzbvKEpB/R4xmpkocxV8MOQliZpX/FHPSnE52qH/OGcN5nYVYxNB ECH/Os+rUVWSRu86uGqJw2rzpYKxLY/GxwYqPX5CJ27BiN4Pv4kZb2PKkzAyV8fAZMKS 8vpSAePNVQ4pAPcFDruhNd42M0jJCHeTfeufXIoT8ImDxccbJs8bbZJXkK4F7KcanAaa IXBQ== 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=82aXtcxDy7/Wl/l7UGwPrNx5XO81lUtjOja44YKXUl0=; b=ILVbRKrpdp7j/l0xtQhPJi2P3UbwQx90xHf7g9qhixkrkFNlXaKJycK3MakF8Rd+m+ RB3tu5jOkaWBIlR7wjuiNXCChzyWp54p2tlTmZl/oYbO9K8MUeJG4LgC1FCXStcmkl+O 64eGuL41tbSjg0PI13u9ge6RrWW2+tlY/xIt1TtPEjRpTiL64bBq4xnq1HC4oGlxDxMK h2EaTOAySKrTGm3yqADUxzKlwv0lyiYEMSArD9Bwk2PAJyYZPNBh0tv7xMrdloGI2sQf mBXi656I74P/xLxxmON5e7lXZl9Ud0TCJbz/Od34jy72Bofa713LgYF01gO6kdz/VknG +kpQ== 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 hg2si12501388ejc.416.2021.12.04.13.34.27; Sat, 04 Dec 2021 13:34:28 -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 848BB68AE34; Sat, 4 Dec 2021 23:34:08 +0200 (EET) 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 3085768A61A for ; Sat, 4 Dec 2021 23:34:00 +0200 (EET) 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 1mtcfP-00HTq0-0I for ffmpeg-devel@ffmpeg.org; Sat, 04 Dec 2021 22:33:59 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id tceRmpEUISgGFtceRm7zmw; Sat, 04 Dec 2021 22:32:59 +0100 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=f8Q2+96M 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=9kAIknLzNnqyaQ3HitYA:9 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 4 Dec 2021 22:32:56 +0100 Message-Id: <20211204213258.11971-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211204213258.11971-1-michael@niedermayer.cc> References: <20211204213258.11971-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfCq3ZsY4VjhxjtlneW7LD7AmJGIRt3/b+HeJ66HRp50/cpcJmbdNTFFMPBVniykhDGrvB3q74NjiZSXVlfQ1RuACusVi9vj9b3IfcrtuxyJsFHj8vMN6 Vl9aa/e4F2/xsNnM3xY5TOfVD+7oDvDOu2KFTTSoUEZNflFX76t5YKun Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/avpacket: Perform fewer reallocations in repeated av_grow_packet() 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: OTB88i7NRipL Fixes: Timeout Fixes: 41446/clusterfuzz-testcase-minimized-ffmpeg_dem_SAMI_fuzzer-4667644540747776 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavcodec/avpacket.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index d8d8fef3b9e..b10498bfc1d 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -142,7 +142,12 @@ int av_grow_packet(AVPacket *pkt, int grow_by) if (new_size + data_offset > pkt->buf->size || !av_buffer_is_writable(pkt->buf)) { - int ret = av_buffer_realloc(&pkt->buf, new_size + data_offset); + int ret; + + if (new_size + data_offset < INT_MAX - new_size/16) + new_size += new_size/16; + + ret = av_buffer_realloc(&pkt->buf, new_size + data_offset); if (ret < 0) { pkt->data = old_data; return ret;