Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Do not allow to read tensor's external_data outside the model directo…
…ry (#4400) * Not allow to read tensor external_data outside the model directory Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Fix formatting errors Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Disable segfaulty test Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Fix cpp tests Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Fix UB while removing ../ Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Fix clang-format Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Check for symlinks only on POSIX systems Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Add specific to Windows external_data test Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Change specific Windows external_data test decorator tofix mypy Signed-off-by: jnovikov <johnnovikov0@gmail.com> * Remove unused pathlib Signed-off-by: jnovikov <johnnovikov0@gmail.com> Signed-off-by: jnovikov <johnnovikov0@gmail.com>
- Loading branch information
Showing
5 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <list> | ||
| #include <utility> | ||
| #include "gtest/gtest.h" | ||
|
|
||
| #include "onnx/common/path.h" | ||
|
|
||
| using namespace ONNX_NAMESPACE; | ||
|
|
||
| namespace ONNX_NAMESPACE { | ||
| namespace Test { | ||
| namespace { | ||
| std::string fix_sep(std::string path) { | ||
| std::string out = path; | ||
| normalize_separator(out); | ||
| return out; | ||
| } | ||
| } // namespace | ||
|
|
||
| TEST(PathTest, CleanRelativePathTest) { | ||
| // Already normal. | ||
| EXPECT_EQ(clean_relative_path("abc"), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("abc/def"), fix_sep("abc/def")); | ||
| EXPECT_EQ(clean_relative_path("a/b/c"), fix_sep("a/b/c")); | ||
| EXPECT_EQ(clean_relative_path("."), fix_sep(".")); | ||
| EXPECT_EQ(clean_relative_path(".."), fix_sep("..")); | ||
| EXPECT_EQ(clean_relative_path("../.."), fix_sep("../..")); | ||
| EXPECT_EQ(clean_relative_path("../../abc"), fix_sep("../../abc")); | ||
| // Remove leading slash | ||
| EXPECT_EQ(clean_relative_path("/abc"), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("/"), fix_sep(".")); | ||
| // Remove trailing slash | ||
| EXPECT_EQ(clean_relative_path("abc/"), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("abc/def/"), fix_sep("abc/def")); | ||
| EXPECT_EQ(clean_relative_path("a/b/c/"), fix_sep("a/b/c")); | ||
| EXPECT_EQ(clean_relative_path("./"), fix_sep(".")); | ||
| EXPECT_EQ(clean_relative_path("../"), fix_sep("..")); | ||
| EXPECT_EQ(clean_relative_path("../../"), fix_sep("../..")); | ||
| EXPECT_EQ(clean_relative_path("/abc/"), fix_sep("abc")); | ||
| // Remove doubled slash | ||
| EXPECT_EQ(clean_relative_path("abc//def//ghi"), fix_sep("abc/def/ghi")); | ||
| EXPECT_EQ(clean_relative_path("//abc"), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("///abc"), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("//abc//"), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("abc//"), fix_sep("abc")); | ||
| // Remove . elements | ||
| EXPECT_EQ(clean_relative_path("abc/./def"), fix_sep("abc/def")); | ||
| EXPECT_EQ(clean_relative_path("/./abc/def"), fix_sep("abc/def")); | ||
| EXPECT_EQ(clean_relative_path("abc/."), fix_sep("abc")); | ||
| // Remove .. elements | ||
| EXPECT_EQ(clean_relative_path("abc/def/ghi/../jkl"), fix_sep("abc/def/jkl")); | ||
| EXPECT_EQ(clean_relative_path("abc/def/../ghi/../jkl"), fix_sep("abc/jkl")); | ||
| EXPECT_EQ(clean_relative_path("abc/def/.."), fix_sep("abc")); | ||
| EXPECT_EQ(clean_relative_path("abc/def/../.."), fix_sep(".")); | ||
| EXPECT_EQ(clean_relative_path("/abc/def/../.."), fix_sep(".")); | ||
| EXPECT_EQ(clean_relative_path("abc/def/../../.."), fix_sep("..")); | ||
| EXPECT_EQ(clean_relative_path("/abc/def/../../.."), fix_sep("..")); | ||
| EXPECT_EQ(clean_relative_path("abc/def/../../../ghi/jkl/../../../mno"), fix_sep("../../mno")); | ||
| EXPECT_EQ(clean_relative_path("/../abc"), fix_sep("../abc")); | ||
| // Combinations | ||
| EXPECT_EQ(clean_relative_path("abc/./../def"), fix_sep("def")); | ||
| EXPECT_EQ(clean_relative_path("abc//./../def"), fix_sep("def")); | ||
| EXPECT_EQ(clean_relative_path("abc/../../././../def"), fix_sep("../../def")); | ||
| } | ||
|
|
||
| } // namespace Test | ||
| } // namespace ONNX_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters