diff --git a/include/WinStd/COM.h b/include/WinStd/COM.h index f1faacbd..132eab9a 100644 --- a/include/WinStd/COM.h +++ b/include/WinStd/COM.h @@ -10,9 +10,10 @@ #include "Common.h" #include -#include +#include #include #include +#include namespace winstd { @@ -1507,7 +1508,9 @@ namespace winstd /// inline _Ret_notnull_ LPSAFEARRAY BuildSAFEARRAY(_In_ VARTYPE vt, _In_opt_ LPCVOID array, _In_ ULONG columns, _In_ ULONG rows) { - const size_t n = columns * rows; + SIZE_T n; + if (FAILED(SIZETMult(columns, rows, &n))) + throw std::invalid_argument("array is too big"); if (!array && n) throw std::invalid_argument("array is NULL"); @@ -1559,7 +1562,9 @@ namespace winstd /// inline VARIANT BuildVBARRAY(_In_ VARTYPE vt, _In_opt_ LPCVOID array, _In_ ULONG columns, _In_ ULONG rows) { - const size_t n = columns * rows; + SIZE_T n; + if (FAILED(SIZETMult(columns, rows, &n))) + throw std::invalid_argument("array is too big"); if (!array && n) throw std::invalid_argument("array is NULL");