@@ -1159,14 +1159,25 @@ HRESULT Mesh::CreateFromVBO(const wchar_t* szFileName, std::unique_ptr<Mesh>& re
1159
1159
if (!result)
1160
1160
return E_OUTOFMEMORY;
1161
1161
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
+
1162
1174
// Read vertices/indices from VBO
1163
1175
std::unique_ptr<vertex_t []> vb (new (std::nothrow) vertex_t [header.numVertices ]);
1164
1176
std::unique_ptr<uint16_t []> ib (new (std::nothrow) uint16_t [header.numIndices ]);
1165
1177
if (!vb || !ib)
1166
1178
return E_OUTOFMEMORY;
1167
1179
1168
- const auto vertSize = static_cast <DWORD>(sizeof (vertex_t ) * header.numVertices );
1169
-
1180
+ const auto vertSize = static_cast <DWORD>(vertSizeBytes);
1170
1181
if (!ReadFile (hFile.get (), vb.get (), vertSize, &bytesRead, nullptr ))
1171
1182
{
1172
1183
return HRESULT_FROM_WIN32 (GetLastError ());
@@ -1175,8 +1186,7 @@ HRESULT Mesh::CreateFromVBO(const wchar_t* szFileName, std::unique_ptr<Mesh>& re
1175
1186
if (bytesRead != vertSize)
1176
1187
return E_FAIL;
1177
1188
1178
- const auto indexSize = static_cast <DWORD>(sizeof (uint16_t ) * header.numIndices );
1179
-
1189
+ const auto indexSize = static_cast <DWORD>(indexSizeBytes);
1180
1190
if (!ReadFile (hFile.get (), ib.get (), indexSize, &bytesRead, nullptr ))
1181
1191
{
1182
1192
return HRESULT_FROM_WIN32 (GetLastError ());
0 commit comments