Skip to content

Commit 4652d66

Browse files
committed
Added guard for 32-bit overflow in spritefont reading
1 parent 624f4d0 commit 4652d66

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Src/BinaryReader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ namespace DirectX
4545
{
4646
static_assert(std::is_standard_layout<T>::value, "Can only read plain-old-data types");
4747

48-
uint8_t const* newPos = mPos + sizeof(T) * elementCount;
48+
uint64_t byteCount = uint64_t(sizeof(T)) * uint64_t(elementCount);
49+
if (byteCount > UINT32_MAX)
50+
throw std::overflow_error("ReadArray");
51+
52+
uint8_t const* newPos = mPos + static_cast<size_t>(byteCount);
4953

5054
if (newPos < mPos)
5155
throw std::overflow_error("ReadArray");

0 commit comments

Comments
 (0)