File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1212#include < cinttypes>
1313#include < cstdint>
1414
15+ #include < c10/util/safe_numerics.h>
16+
1517#include < executorch/runtime/core/error.h>
1618#include < executorch/runtime/platform/assert.h>
1719#include < executorch/runtime/platform/compiler.h>
1820#include < executorch/runtime/platform/log.h>
1921#include < executorch/runtime/platform/profiler.h>
2022
23+
2124namespace executorch {
2225namespace runtime {
2326
@@ -137,7 +140,17 @@ class MemoryAllocator {
137140 // Some users of this method allocate lists of pointers, causing the next
138141 // line to expand to `sizeof(type *)`, which triggers a clang-tidy warning.
139142 // NOLINTNEXTLINE(bugprone-sizeof-expression)
140- return static_cast <T*>(this ->allocate (size * sizeof (T), alignment));
143+ size_t bytes_size = 0 ;
144+ bool overflow =
145+ c10::mul_overflows (size, sizeof (T), &bytes_size);
146+ if (overflow) {
147+ ET_LOG (
148+ Error,
149+ " Failed to allocate list of type %zu: size * sizeof(T) overflowed" ,
150+ size);
151+ return nullptr ;
152+ }
153+ return static_cast <T*>(this ->allocate (bytes_size, alignment));
141154 }
142155
143156 // Returns the allocator memory's base address.
You can’t perform that action at this time.
0 commit comments