From patchwork Mon May 25 14:07:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19856 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AB75C44A859 for ; Mon, 25 May 2020 17:08:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 97FEE68A821; Mon, 25 May 2020 17:08:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D8D3A68A471 for ; Mon, 25 May 2020 17:08:34 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id v19so142353wmj.0 for ; Mon, 25 May 2020 07:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CHDkAGSWWcu8b0zzoZBZeHiN/ATFViKQ+9MbP2Ebvvc=; b=tKf0YwF63prNwRQ7l86Dv+V5WiYpDx9yDiLnyNCFKrn4lSv93AdsWk2K4DK4i+G7Y/ cMPWZRcd64+JzakV7XudfA2eLi3u7EOFu8K+7KzDHDGNSE0s7B7qDaqZMN0bzvSvHe4z ozExjOOY1YZhyVdQ5GV4WLzyuiChR4ecfXJb1fOB9qiu3sBj1c4IDpzMHNDpVE2t7vPb TaOgquNORF08rbsjuPnsx9TgOL1HGBxtI17w8AjYNY1kITd3UbNiYAmSDHpmLXSmwylI JRBwsL3GjdW06DH4U8em5Dg59zD8MVXdCu3f6FU/2sN5J3kuRoITi0lWaj8URvSnzcPO sdNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CHDkAGSWWcu8b0zzoZBZeHiN/ATFViKQ+9MbP2Ebvvc=; b=HgVLHb85+Lqy+BOm5pmfImyksY90qVTpckjMopQhrrUWNTMCV0KBk3ddjAB/oceHTe DW9LnFuvV0B+FlaQkQUojtIh5mhoH13z5wpC6H1D7Vj+I1uIDbcHZKsLO+zCVxBRfwbS IZn4MeLbjG/QNu+QBZEqCZpFCEutz6P2t7f1hfZLk47cebZawdgvhS5hEDWbpYKfcJvy xTBv27fjj52qZ7DnkF3diGUp8HsDrXzhEvuCNXvliH5Z+N6T+oGzKvPcACb/NyZPrSxw rZ8J/kBR+y7iEGzUA+/dRC/FpE+qdxxGK5ohEHBfDLD38vqH3eTeh1xvvtAshKCOEkne yuNQ== X-Gm-Message-State: AOAM533nGUaXTWXNKWBUNMdcC6B7zPclTQui7co1JP4qCSSr3pterTaz GJWUL0+DX9k3+Mn/YbfzS+n7wSsH X-Google-Smtp-Source: ABdhPJwDAnx96T1vvy4dppU04T9ktqWjpdvLuFudLMGBti7IRHugJDx8qUs9NRobZ5SJUuhQaCAcUA== X-Received: by 2002:a1c:9e43:: with SMTP id h64mr25083615wme.0.1590415714019; Mon, 25 May 2020 07:08:34 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id x186sm10355218wmg.8.2020.05.25.07.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 07:08:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 May 2020 16:07:59 +0200 Message-Id: <20200525140801.18889-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525140801.18889-1-andreas.rheinhardt@gmail.com> References: <20200525140801.18889-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/aviobuf: Stop restricting dynamic buffer sizes to INT_MAX/2 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This has originally been done in 568e18b15e2ddf494fd8926707d34ca08c8edce5 as a precaution against integer overflows, but it is actually easy to support the full range of int without overflows. Signed-off-by: Andreas Rheinhardt --- libavformat/aviobuf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index fcde7e8510..688c7c50fd 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1276,7 +1276,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) /* reallocate buffer if needed */ new_size = (unsigned)d->pos + buf_size; - if (new_size < d->pos || new_size > INT_MAX/2) + if (new_size < d->pos || new_size > INT_MAX) return -1; if (new_size > d->allocated_size) { unsigned new_allocated_size = d->allocated_size ? d->allocated_size @@ -1285,6 +1285,8 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) while (new_size > new_allocated_size) new_allocated_size += new_allocated_size / 2 + 1; + new_allocated_size = FFMIN(new_allocated_size, INT_MAX); + if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) { d->allocated_size = 0; d->size = 0;