|
9 | 9 | #include <executorch/runtime/executor/method_meta.h>
|
10 | 10 |
|
11 | 11 | #include <cstdlib>
|
12 |
| -#include <filesystem> |
| 12 | +#include <limits> |
| 13 | +#include <vector> |
13 | 14 |
|
14 | 15 | #include <executorch/extension/data_loader/file_data_loader.h>
|
15 | 16 | #include <executorch/runtime/core/exec_aten/exec_aten.h>
|
16 | 17 | #include <executorch/runtime/executor/program.h>
|
| 18 | +#include <executorch/test/utils/DeathTest.h> |
17 | 19 | #include <gtest/gtest.h>
|
18 | 20 |
|
19 | 21 | using namespace ::testing;
|
20 | 22 | using executorch::runtime::Error;
|
21 | 23 | using executorch::runtime::MethodMeta;
|
22 | 24 | using executorch::runtime::Program;
|
23 | 25 | using executorch::runtime::Result;
|
| 26 | +using executorch::runtime::Span; |
24 | 27 | using executorch::runtime::TensorInfo;
|
25 | 28 | using torch::executor::util::FileDataLoader;
|
26 | 29 |
|
| 30 | +namespace executorch { |
| 31 | +namespace runtime { |
| 32 | +namespace testing { |
| 33 | +// Provides access to private TensorInfo methods. |
| 34 | +class TensorInfoTestFriend final { |
| 35 | + public: |
| 36 | + ET_NODISCARD static TensorInfo get( |
| 37 | + Span<const int32_t> sizes, |
| 38 | + Span<const uint8_t> dim_order, |
| 39 | + executorch::aten::ScalarType scalar_type, |
| 40 | + const bool is_memory_planned, |
| 41 | + executorch::aten::string_view name) { |
| 42 | + return TensorInfo( |
| 43 | + Span<const int32_t>(sizes.data(), sizes.size()), |
| 44 | + Span<const uint8_t>(dim_order.data(), dim_order.size()), |
| 45 | + scalar_type, |
| 46 | + is_memory_planned, |
| 47 | + name); |
| 48 | + } |
| 49 | +}; |
| 50 | +} // namespace testing |
| 51 | +} // namespace runtime |
| 52 | +} // namespace executorch |
| 53 | + |
27 | 54 | class MethodMetaTest : public ::testing::Test {
|
28 | 55 | protected:
|
29 | 56 | void load_program(const char* path, const char* module_name) {
|
@@ -163,3 +190,25 @@ TEST_F(MethodMetaTest, MethodMetaAttribute) {
|
163 | 190 | auto bad_access = method_meta->attribute_tensor_meta(1);
|
164 | 191 | ASSERT_EQ(bad_access.error(), Error::InvalidArgument);
|
165 | 192 | }
|
| 193 | + |
| 194 | +TEST_F(MethodMetaTest, TensorInfoSizeOverflow) { |
| 195 | + // Create sizes that will cause overflow when multiplied |
| 196 | + std::vector<int32_t> overflow_sizes = { |
| 197 | + std::numeric_limits<int32_t>::max(), |
| 198 | + std::numeric_limits<int32_t>::max(), |
| 199 | + std::numeric_limits<int32_t>::max(), |
| 200 | + std::numeric_limits<int32_t>::max(), |
| 201 | + }; |
| 202 | + |
| 203 | + // Create a minimal dim_order |
| 204 | + std::vector<uint8_t> dim_order = {0, 1, 2, 3}; |
| 205 | + |
| 206 | + // Create a TensorInfo with the overflow sizes and expect it to fail. |
| 207 | + ET_EXPECT_DEATH(executorch::runtime::testing::TensorInfoTestFriend::get( |
| 208 | + Span<const int32_t>(overflow_sizes.data(), overflow_sizes.size()), |
| 209 | + Span<const uint8_t>(dim_order.data(), dim_order.size()), |
| 210 | + executorch::aten::ScalarType::Float, |
| 211 | + false, // is_memory_planned |
| 212 | + executorch::aten::string_view{nullptr, 0}),""); |
| 213 | + |
| 214 | +} |
0 commit comments