@@ -1159,14 +1159,25 @@ HRESULT Mesh::CreateFromVBO(const wchar_t* szFileName, std::unique_ptr<Mesh>& re
11591159 if (!result)
11601160 return E_OUTOFMEMORY;
11611161
1162+ const uint64_t vertSizeBytes = static_cast <uint64_t >(header.numVertices ) * sizeof (vertex_t );
1163+ if (vertSizeBytes > UINT32_MAX)
1164+ {
1165+ return HRESULT_FROM_WIN32 (ERROR_ARITHMETIC_OVERFLOW);
1166+ }
1167+
1168+ const uint64_t indexSizeBytes = static_cast <uint64_t >(header.numIndices ) * sizeof (uint16_t );
1169+ if (indexSizeBytes > UINT32_MAX)
1170+ {
1171+ return HRESULT_FROM_WIN32 (ERROR_ARITHMETIC_OVERFLOW);
1172+ }
1173+
11621174 // Read vertices/indices from VBO
11631175 std::unique_ptr<vertex_t []> vb (new (std::nothrow) vertex_t [header.numVertices ]);
11641176 std::unique_ptr<uint16_t []> ib (new (std::nothrow) uint16_t [header.numIndices ]);
11651177 if (!vb || !ib)
11661178 return E_OUTOFMEMORY;
11671179
1168- const auto vertSize = static_cast <DWORD>(sizeof (vertex_t ) * header.numVertices );
1169-
1180+ const auto vertSize = static_cast <DWORD>(vertSizeBytes);
11701181 if (!ReadFile (hFile.get (), vb.get (), vertSize, &bytesRead, nullptr ))
11711182 {
11721183 return HRESULT_FROM_WIN32 (GetLastError ());
@@ -1175,8 +1186,7 @@ HRESULT Mesh::CreateFromVBO(const wchar_t* szFileName, std::unique_ptr<Mesh>& re
11751186 if (bytesRead != vertSize)
11761187 return E_FAIL;
11771188
1178- const auto indexSize = static_cast <DWORD>(sizeof (uint16_t ) * header.numIndices );
1179-
1189+ const auto indexSize = static_cast <DWORD>(indexSizeBytes);
11801190 if (!ReadFile (hFile.get (), ib.get (), indexSize, &bytesRead, nullptr ))
11811191 {
11821192 return HRESULT_FROM_WIN32 (GetLastError ());
0 commit comments