From 574ff66c01f4248e40bd027177afa0a9ff44057e Mon Sep 17 00:00:00 2001 From: bo huang <24309515+bo-huang@users.noreply.github.com> Date: Tue, 21 Apr 2020 14:23:42 +0800 Subject: [PATCH] add safty check 4 annoy load index (#2009) Signed-off-by: bo-huang <1013767522@qq.com> --- core/src/index/thirdparty/annoy/src/annoylib.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/index/thirdparty/annoy/src/annoylib.h b/core/src/index/thirdparty/annoy/src/annoylib.h index eeed105780..d51a56afe2 100644 --- a/core/src/index/thirdparty/annoy/src/annoylib.h +++ b/core/src/index/thirdparty/annoy/src/annoylib.h @@ -1140,6 +1140,10 @@ public: _n_nodes = (S)(index_size / _s); // _nodes = (Node*)malloc(_s * _n_nodes); _nodes = (Node*)malloc((size_t)index_size); + if (_nodes == nullptr) { + set_error_from_errno(error, "alloc failed when load_index 4 annoy"); + return false; + } memcpy(_nodes, index_data, (size_t)index_size); // Find the roots by scanning the end of the file and taking the nodes with most descendants