From patchwork Tue Jan 2 01:00:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 7065 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp14113794jad; Mon, 1 Jan 2018 17:01:22 -0800 (PST) X-Google-Smtp-Source: ACJfBovmQx+S4/dqz8Mmt1HKrDuoY7IXto5+z366j7C2Q/nC6dDqioSop1fT7B7aAAXZ8M6bT9jq X-Received: by 10.28.226.214 with SMTP id z205mr36609709wmg.149.1514854882313; Mon, 01 Jan 2018 17:01:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514854882; cv=none; d=google.com; s=arc-20160816; b=0bMhX/nFu3AsYozTY5UHzPswdnz+vkW2xR9FgwKOdAiVSKrYJOxzn6TFRDjf7whLJI fM7ZD4U5rAqyEWyr35sEEZ+g4RknfbZlJu/LujLDCu8bueexOAE5iVzp2vKqUuG0JrF7 lFKDjtqnecdAAfQg9fpf7pGvAgCf7bm53BqzGbz15ZRq8UGOspiGfM2TdAXwYtUPCM6G Fb6VKQhsXC1Q7UgAWDhAaxF7EBITaaNufMvabPAm+9Pv+ZXwKgFY0a1bY84F2kwFQUUL ixsqvn2CvXRyevMnnQ7LUpeCOrrKnu1a8rc0A/qxZARmP17AjRA0L6jSGoZiZeEJQKXs KrCg== 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:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=ny3r57YwGucVU4MM/O3HUYsFQLDHX7WmF0gXYWLckPo=; b=g+4lAVg3+eaQ2WAYj2fvT1jc53K2wd9j26iaohJxaNRYyoiY4BeZ9MyTx0AeZU2t39 LSMCXckPsvGghOOTf4YK/g2Ap/0m+4dKhB9rLZUImpg4FeD9wQaEPEPRELXpZl1v7JCQ 54OKFE9TL+JXyrqjo0AJwM683fo5YdmmAU8lJfi6cBOc4DV+aJ3Gpu1CLWSG/HM9D8pI BW8o94DyRTOIeVY8YXeyb/Cqrp0zin++GPrEvidqol69IekCHSRO5mNE1Raf/hThfGDH uWUz/b80mD3N8aIHkpM18bbdRfph4m7x7Xi/VvkfHOUYFURiWDnBxxBL4KbtiP+21s2T N/UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=d3d6DcB9; 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 u70si19221213wmf.98.2018.01.01.17.01.21; Mon, 01 Jan 2018 17:01:22 -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=d3d6DcB9; 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 CA58F6806C5; Tue, 2 Jan 2018 03:01:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f41.google.com (mail-it0-f41.google.com [209.85.214.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D70B0680470 for ; Tue, 2 Jan 2018 03:00:56 +0200 (EET) Received: by mail-it0-f41.google.com with SMTP id d16so37975820itj.1 for ; Mon, 01 Jan 2018 17:01:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=qlYo7SJ7NyE+FQZ57ctDp0RvPUnPGi5e/O3uIlmrTGs=; b=d3d6DcB9HOe+Uza53ZliCy/I4rzQqz8K6UFN8cssKgg85yu9LOnSlfM13e7LURvSCW pwhSXcI/5DeBGqW4s30ziOiZ4/zT/hixR71ZNqri3qT80WdmX3GLfMbng4VPUmlbzCS9 zPbTyggLGr6gw+Q0aK7Jz1AvNRROMPn98xdkstkJ6fUiUyDEO7BhQDU2OAB5OGjeBIGM 1/dUKtLXwt3v1XRF0L5JRg3EjxgAqnOWAyRXQjPsqMDv1BMXVY9YaiNFqqkilD2v+IIm 0SATez9iHGQHZjA+9sb8BmkBx/XA9HYdcFzUabsbUUbAjhNMcxq2Orn0PnQGwFZzug3C KqEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=qlYo7SJ7NyE+FQZ57ctDp0RvPUnPGi5e/O3uIlmrTGs=; b=tifyaNyHYIgrA+oT9MMS8+3xsYnpfH6S2YTO3r9IckhWypWUJxCllbBvGWuKvSqzWH xjqryZdTgFl8GHJ/uxpTXB0ifVGLwp1IziqvXuSv2eNoZE14RUad7iyF00ofDrJXJk8c FjHy2IbYfOgwYAhUDx/5EvofBf5TuTMzHph+gmbWx9GNMthTlkV4310dWKVsBc2GOljh oyRtPW8zuBiFZBRBMxHnpxHUFtYc04SeZDAr6cT9mRI4AQDFvWAOOnF2U8vaimCdM9pS idzx1knVw35Y8K07vutrpO/WGixHJlo576M2teVgW7P93fgIXn8qBXSyUrSRblt02L61 FZSQ== X-Gm-Message-State: AKGB3mKjrv8gu3cVlr+cisMQmpvrtS/SiLAHeEbTZt/hagOJi3EbXNAJ jpYTF8MN6sXfkE3Bq2I295QmtP4g1n8ZA7+Hazw= X-Received: by 10.36.110.22 with SMTP id w22mr59462469itc.113.1514854871071; Mon, 01 Jan 2018 17:01:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.119.211 with HTTP; Mon, 1 Jan 2018 17:00:50 -0800 (PST) In-Reply-To: <20180102001406.GV4926@michaelspb> References: <20180102001406.GV4926@michaelspb> From: Carl Eugen Hoyos Date: Tue, 2 Jan 2018 02:00:50 +0100 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH][RFC]lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc() 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" 2018-01-02 1:14 GMT+01:00 Michael Niedermayer : > On Mon, Jan 01, 2018 at 11:10:57PM +0100, Carl Eugen Hoyos wrote: >> Hi! >> >> Similar reason as last mem.c patch: av_fast_realloc() can currently >> fail in situations where the allocation is possible and allowed. >> The patch does not change behaviour for the failure case, if this is >> wanted, it should be done separately. >> >> Please comment, Carl Eugen > >> mem.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> 7529e1d584c62ece463f4461279ea6e3973162c9 0001-lavu-mem-Allow-allocations-close-to-max_alloc_size-w.patch >> From ac69f4e8402f7c7ee6df09c0450354e2bb900e5a Mon Sep 17 00:00:00 2001 >> From: Carl Eugen Hoyos >> Date: Mon, 1 Jan 2018 23:04:58 +0100 >> Subject: [PATCH] lavu/mem: Allow allocations close to max_alloc_size with >> av_fast_realloc(). >> >> --- >> libavutil/mem.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/libavutil/mem.c b/libavutil/mem.c >> index 0729e1d..934987f 100644 >> --- a/libavutil/mem.c >> +++ b/libavutil/mem.c >> @@ -466,7 +466,10 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) >> if (min_size <= *size) >> return ptr; >> >> - min_size = FFMAX(min_size + min_size / 16 + 32, min_size); >> + if (min_size > (max_alloc_size - 32)) >> + return NULL; > > This failure mode differs from the existing in what it does with *size New patch attached. Thank you, Carl Eugen From 9586fb78e4b304923569a09fb275ece0531726e0 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Tue, 2 Jan 2018 01:58:35 +0100 Subject: [PATCH] lavu/mem: Allow allocations close to max_alloc_size with av_fast_realloc(). --- libavutil/mem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libavutil/mem.c b/libavutil/mem.c index 0729e1d..6149755 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -466,7 +466,12 @@ void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) if (min_size <= *size) return ptr; - min_size = FFMAX(min_size + min_size / 16 + 32, min_size); + if (min_size > max_alloc_size - 32) { + *size = 0; + return NULL; + } + + min_size = FFMIN(max_alloc_size - 32, FFMAX(min_size + min_size / 16 + 32, min_size)); ptr = av_realloc(ptr, min_size); /* we could set this to the unmodified min_size but this is safer -- 1.7.10.4