From patchwork Sat Dec 30 13:44:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 7031 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp11635003jad; Sat, 30 Dec 2017 05:45:24 -0800 (PST) X-Google-Smtp-Source: ACJfBotB6BcokrGlagN9cQ7cFmCLW1gOyZRg7SSwMC4Ckgi7OMm9GOOD0IANOFqVmH8WC+UEvrmM X-Received: by 10.223.185.51 with SMTP id k48mr38922028wrf.270.1514641524069; Sat, 30 Dec 2017 05:45:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514641524; cv=none; d=google.com; s=arc-20160816; b=pQi+0tHaSMDtVSEvX2ZHUw9PcjR0XN7FALlsjdESoMD7VOJJzw1bBJW8PbFuuSulZ7 kLmwRiCnnRfDvUMRjQ54uLT+c6mrUUk6N+l24EZDjk1pCR+R3UuCiAPCs7RNs1lAgTIp ZriYLhS8QjJRDoBTAua9Q8dKvccF+8e8J9gjnwUPb7p/M1Pnn06XgtIVSeg9eCGnQsqZ 7T5tMh+sgekBdPH3nwcDVV91Py0iy2x7+x97Ko+nK1f4+EZ2S2mhuHbIW4uJiJoCVt0D bVJI0YAzeGBn/DDavp2V14bHX261Hw+l6yTnHokyM0nzcN+OGNynRhDM8TR3EK5PVVg5 FxDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to :arc-authentication-results; bh=jAy+oZuIA5Ct5UNBRy+zhtuekwx5P2SmHnF1Hw6rND4=; b=fzigwW6oYeSw86z45wuEADMOfNMWjzidGvjvbOa/ZlB//3+NwnjOHMKG/GE1XjQlWS 47j+1GaViNIRhVReYuJpNvIgvaMp6DRGYND+xaeoI66gEn+YA9InpFE4T+gEYNFgxvPT ign4fPymUXpP6zoey5sjv2GG7LgtivZ7T9tYhW2QkO2jhGjwejNvwP4fZkTKtDGRK/qY TJOhqpaCvJPUnq80q+AVkZwRsqhN/d7SDxiLzndMdV/m6twyFqEA4N2YxjHzKb1er6Vs sl9dvqTd+I3zGwx95lFXCBPS3l/TOvjnlHXuTXGKdI+K6G4Qos+8bLPr+ETUZdQwolnK VxNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qTUuWRzV; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 6si18031908wmk.223.2017.12.30.05.45.23; Sat, 30 Dec 2017 05:45:24 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qTUuWRzV; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 99FBE689C89; Sat, 30 Dec 2017 15:45:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f49.google.com (mail-it0-f49.google.com [209.85.214.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 545C6689A61 for ; Sat, 30 Dec 2017 15:45:01 +0200 (EET) Received: by mail-it0-f49.google.com with SMTP id m11so5956299iti.1 for ; Sat, 30 Dec 2017 05:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=51RBpV/STsa7r/6EoNhoISjdKL1F8dPhtanv2RmWQ1U=; b=qTUuWRzV8gidDU+MvNQAorYWvleLvtk/HnrVt4NRIWg3atKpy/XaGP9N7ujlDe+PA6 gnNPAOjCuljDd1gUIyuHszfr/0MghmGbrFqjlldoDt7W7P5GioEuHwkayRP1wr8GVjK7 hyncDgiZsSDnjhab+bBeJyy6F5B+eCn7qm0Nx3z1wYWzFjD/dGzhibvROz0pS9/c51wH Kdpznw7HmZGICQ9wVZILQfCzAqHYMR/N7l5BrNSJocG3Y8Oi5rjBvW9MbU0mj6FXk7fX y/u3Dy3IJAvlDQQb8EfBeQ0cs0EDXTCISTD5CYhP6n7v3CJP5XPRkFyTM9LvCCd55yX2 H/dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=51RBpV/STsa7r/6EoNhoISjdKL1F8dPhtanv2RmWQ1U=; b=nGOnkQDEY8s1s6gG/Xe6aa/yzhHxt9MGAvN92QY2yfgGUKSW/bg6/eeE7snELppc2F GHT5w2EY0smzBNFPHmnGdNQR+3v5Pr/IeBjh73UUokWopcHmyEAuTEVy5xPAn44hxVCM l+MsyxsOwtBmQJOtqktTKMxlKDM9jbazC0Kuir0xDvWik7TPvySNe9s/zPUnMMYomVK5 lmyhEROmWxM8mvhZb1ujfkD/uB1KwP36DlNoM8dyGlZTQygfKs4KjFW7uHlOnKA5jWBp A9g1imyqEc3Qo8AjR2vC+vPEaUR227Db4aAS4142S4EqRUKmQLhDId7aO+80Jklz8ED8 Uywg== X-Gm-Message-State: AKGB3mIZRJ8TrOdsVg4mI3w/sCNT+XHqjLbgDZBtwZX4vGCYRQkb2eSU RwUf09Dz4Xm2ydQl5+/qDkAkLgIDAY06mtubSq0= X-Received: by 10.36.123.134 with SMTP id q128mr50599793itc.80.1514641514734; Sat, 30 Dec 2017 05:45:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.119.211 with HTTP; Sat, 30 Dec 2017 05:44:54 -0800 (PST) From: Carl Eugen Hoyos Date: Sat, 30 Dec 2017 14:44:54 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH][RFC]lavu/mem: Do not realloc in av_fast_alloc() if size == min_size 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi! FFmpeg has an arbitrary allocation limit (2G iirc), av_fast_realloc() increases the allocation even if the requested is equal the already allocated size. I believe this can lead to unnecessary OOM (no testcase) if the requested (and already allocated) size is close to our limit. Additionally, this avoids an over-allocation for the mov stts patch I just sent. Attached patch changes the behaviour introduced 15 years ago. Please comment, Carl Eugen From 0ad7a0517c69d04a4443e66eeec802bda21aea55 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sat, 30 Dec 2017 14:38:33 +0100 Subject: [PATCH] lavu/mem: Do not realloc in av_fast_realloc() if size == min_size. This can avoid OOM for min_size close to FFmpeg's arbitrary alloc limits. --- libavutil/mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/mem.c b/libavutil/mem.c index 79e8b59..0729e1d 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -463,7 +463,7 @@ void av_memcpy_backptr(uint8_t *dst, int back, int cnt) void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) { - if (min_size < *size) + if (min_size <= *size) return ptr; min_size = FFMAX(min_size + min_size / 16 + 32, min_size); -- 1.7.10.4