ref: e6d2dc12adcabb5e387188f616f31e3219660029
parent: 1cb039529d4c1b535093c759850835fae794d424
author: kyslov <kyslov@google.com>
date: Fri Dec 21 07:04:04 EST 2018
Bound the total allocated memory of frame buffer This CL allows to limit memory consumption of the frame buffer pool. As the result if compiled with VPX_MAX_ALLOCABLE_MEMORY set codec will fail if frame resolution requires more memory This is backported CL aae2183cb58b60d01b8e4e15269ee9f48dd72908 from aomedia Tested: configure --extra-cflags="-DVPX_MAX_ALLOCABLE_MEMORY=536870912" make ./test_libvpx BUG=webm:1579 Change-Id: Ic62213b600a7562917d5a339a344ad8db4b6f481
--- a/vpx_scale/generic/yv12config.c
+++ b/vpx_scale/generic/yv12config.c
@@ -15,6 +15,9 @@
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem.h"
+#if defined(VPX_MAX_ALLOCABLE_MEMORY)
+#include "vp9/common/vp9_onyxc_int.h"
+#endif // VPX_MAX_ALLOCABLE_MEMORY
/****************************************************************************
* Exports
****************************************************************************/
@@ -184,6 +187,13 @@
#endif // CONFIG_VP9_HIGHBITDEPTH
uint8_t *buf = NULL;
+
+#if defined(VPX_MAX_ALLOCABLE_MEMORY)
+ // The decoder may allocate REF_FRAMES frame buffers in the frame buffer
+ // pool. Bound the total amount of allocated memory as if these REF_FRAMES
+ // frame buffers were allocated in a single allocation.
+ if (frame_size > VPX_MAX_ALLOCABLE_MEMORY / REF_FRAMES) return -1;
+#endif // VPX_MAX_ALLOCABLE_MEMORY
// frame_size is stored in buffer_alloc_sz, which is a size_t. If it won't
// fit, fail early.