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 <ceffm...@gmail.com> 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
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel