Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Fix exceeds maximum supported size in allocator (#37467)

Oleg Pipikin35b39f515dfa
diff --git a/src/core/src/runtime/allocator.cpp b/src/core/src/runtime/allocator.cpp
index ce158ecb077..a61aa2981c9 100644
--- a/src/core/src/runtime/allocator.cpp
+++ b/src/core/src/runtime/allocator.cpp
@@ -7,9 +7,16 @@
#include "openvino/core/except.hpp"
namespace ov {
+namespace {
+constexpr uint64_t max_supported_allocation_size = uint64_t{1} << 40; // 1 TiB
+} // namespace
struct DefaultAllocator {
void* allocate(const size_t bytes, const size_t alignment) {
+ OPENVINO_ASSERT(static_cast<uint64_t>(bytes) <= max_supported_allocation_size,
+ "Requested allocation size ",
+ bytes,
+ " exceeds maximum supported allocation size");
if (alignment == alignof(max_align_t)) {
return ::operator new(bytes);
} else {
diff --git a/src/core/tests/ov_default_allocator_test.cpp b/src/core/tests/ov_default_allocator_test.cpp
index 60747a63e7d..4328337f570 100644
--- a/src/core/tests/ov_default_allocator_test.cpp
+++ b/src/core/tests/ov_default_allocator_test.cpp
@@ -71,4 +71,16 @@ TEST_F(OVDefaultAllocatorTest, compareIfImplIsNull) {
EXPECT_FALSE(a2 == a1);
OV_EXPECT_THROW(std::ignore = (a1 == a2), ov::Exception, _);
}
+
+TEST_F(OVDefaultAllocatorTest, throwsOnAllocationLargerThanOneTiB) {
+ if (sizeof(size_t) < sizeof(uint64_t)) {
+ GTEST_SKIP() << "Allocation larger than 1 TiB cannot be represented by size_t";
+ }
+
+ ov::Allocator allocator;
+ constexpr uint64_t one_tib = uint64_t{1} << 40;
+ OV_EXPECT_THROW_HAS_SUBSTRING(std::ignore = allocator.allocate(static_cast<size_t>(one_tib + 1)),
+ ov::Exception,
+ "exceeds maximum supported allocation size");
+}
} // namespace ov::test