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