|
| 1 | +diff -urpN pytorch-v2.0.0/third_party/onnx/onnx/common/assertions.cc b/third_party/onnx/onnx/common/assertions.cc |
| 2 | +--- pytorch-v2.0.0/third_party/onnx/onnx/common/assertions.cc 2023-04-03 15:46:03.000000000 -0400 |
| 3 | ++++ b/third_party/onnx/onnx/common/assertions.cc 2024-04-22 13:15:05.240131051 -0400 |
| 4 | +@@ -6,6 +6,7 @@ |
| 5 | + // Adventurous users should note that the APIs will probably change. |
| 6 | + |
| 7 | + #include "onnx/common/assertions.h" |
| 8 | ++#include <array> |
| 9 | + #include <cstdarg> |
| 10 | + #include <cstdio> |
| 11 | + #include "onnx/common/common.h" |
| 12 | +@@ -13,16 +14,20 @@ |
| 13 | + namespace ONNX_NAMESPACE { |
| 14 | + |
| 15 | + std::string barf(const char* fmt, ...) { |
| 16 | +- char msg[2048]; |
| 17 | ++ constexpr size_t buffer_size = 2048; |
| 18 | ++ std::array<char, buffer_size> msg{}; |
| 19 | + va_list args; |
| 20 | + |
| 21 | + va_start(args, fmt); |
| 22 | +- // Although vsnprintf might have vulnerability issue while using format string with overflowed length, |
| 23 | +- // it should be safe here to use fixed length for buffer "msg". No further checking is needed. |
| 24 | +- vsnprintf(msg, 2048, fmt, args); |
| 25 | ++ |
| 26 | ++ // use fixed length for buffer "msg" to avoid buffer overflow |
| 27 | ++ vsnprintf(static_cast<char*>(msg.data()), msg.size() - 1, fmt, args); |
| 28 | ++ |
| 29 | ++ // ensure null-terminated string to avoid out of bounds read |
| 30 | ++ msg.back() = '\0'; |
| 31 | + va_end(args); |
| 32 | + |
| 33 | +- return std::string(msg); |
| 34 | ++ return std::string(msg.data()); |
| 35 | + } |
| 36 | + |
| 37 | + void throw_assert_error(std::string& msg) { |
| 38 | +diff -urpN pytorch-v2.0.0/third_party/onnx-tensorrt/third_party/onnx/onnx/common/assertions.cc b/third_party/onnx-tensorrt/third_party/onnx/onnx/common/assertions.cc |
| 39 | +--- pytorch-v2.0.0/third_party/onnx-tensorrt/third_party/onnx/onnx/common/assertions.cc 2023-04-03 15:46:03.000000000 -0400 |
| 40 | ++++ b/third_party/onnx-tensorrt/third_party/onnx/onnx/common/assertions.cc 2024-04-22 13:14:01.512210959 -0400 |
| 41 | +@@ -1,6 +1,7 @@ |
| 42 | + // ATTENTION: The code in this file is highly EXPERIMENTAL. |
| 43 | + // Adventurous users should note that the APIs will probably change. |
| 44 | + |
| 45 | ++#include <array> |
| 46 | + #include <cstdarg> |
| 47 | + #include <cstdio> |
| 48 | + |
| 49 | +@@ -9,14 +10,20 @@ |
| 50 | + namespace ONNX_NAMESPACE { |
| 51 | + |
| 52 | + std::string barf(const char* fmt, ...) { |
| 53 | +- char msg[2048]; |
| 54 | ++ constexpr size_t buffer_size = 2048; |
| 55 | ++ std::array<char, buffer_size> msg{}; |
| 56 | + va_list args; |
| 57 | + |
| 58 | + va_start(args, fmt); |
| 59 | +- vsnprintf(msg, 2048, fmt, args); |
| 60 | ++ |
| 61 | ++ // use fixed length for buffer "msg" to avoid buffer overflow |
| 62 | ++ vsnprintf(static_cast<char*>(msg.data()), msg.size() - 1, fmt, args); |
| 63 | ++ |
| 64 | ++ // ensure null-terminated string to avoid out of bounds read |
| 65 | ++ msg.back() = '\0'; |
| 66 | + va_end(args); |
| 67 | + |
| 68 | +- return std::string(msg); |
| 69 | ++ return std::string(msg.data()); |
| 70 | + } |
| 71 | + |
| 72 | + void throw_assert_error(std::string& msg) { |
0 commit comments