Skip to content

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

intel_npu: reject oversized blob size before allocation in allocate_aligned_tensor (#37186)

Deepak Bhagat5d13a5c7fb98
diff --git a/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp b/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp
index d10c6fb3bfc..ac952bd3ad2 100644
--- a/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp
+++ b/src/plugins/intel_npu/src/plugin/src/blob_format_importers.cpp
@@ -20,6 +20,16 @@ namespace {
using namespace intel_npu;
+ov::Tensor allocate_aligned_tensor(size_t blobSize) {
+ ov::Allocator customAllocator{utils::AlignedAllocator{utils::STANDARD_PAGE_SIZE}};
+ if (blobSize > static_cast<decltype(blobSize)>(std::numeric_limits<std::streamsize>::max())) {
+ OPENVINO_THROW("Blob size is too large to be represented on a std::streamsize!");
+ }
+ ov::Tensor tensor(ov::element::u8, ov::Shape{blobSize}, customAllocator);
+
+ return tensor;
+}
+
constexpr std::string_view HANDLER_FACTOR_LOGGER_NAME = "blob_format_importer_factory";
constexpr std::string_view RAW_BLOB_HANDLER_LOGGER_NAME = "RawBlobImporter";
constexpr std::string_view BLOB_V1_HADNLER_LOGGER_NAME = "BlobFormatV1Importer";
@@ -35,16 +45,6 @@ constexpr std::string_view DECRYPTING_PAYLOAD_MESSAGE = "Decrypting the compiler
const std::vector<size_t> CONSTANT_NODE_DUMMY_SHAPE{1};
-ov::Tensor allocate_aligned_tensor(size_t blobSize) {
- ov::Allocator customAllocator{utils::AlignedAllocator{utils::STANDARD_PAGE_SIZE}};
- ov::Tensor tensor(ov::element::u8, ov::Shape{blobSize}, customAllocator);
- if (blobSize > static_cast<decltype(blobSize)>(std::numeric_limits<std::streamsize>::max())) {
- OPENVINO_THROW("Blob size is too large to be represented on a std::streamsize!");
- }
-
- return tensor;
-}
-
/**
* @brief Special case for PERF_COUNT as it requires compiler_type detection in case it is still set to PREFER_PLUGIN
*/
diff --git a/src/plugins/intel_npu/tests/unit/npu/blob_format_importers.cpp b/src/plugins/intel_npu/tests/unit/npu/blob_format_importers.cpp
index 8b0e209e68c..02938868f91 100644
--- a/src/plugins/intel_npu/tests/unit/npu/blob_format_importers.cpp
+++ b/src/plugins/intel_npu/tests/unit/npu/blob_format_importers.cpp
@@ -6,6 +6,7 @@
#include <gtest/gtest.h>
+#include <limits>
#include <sstream>
#include <string_view>