Skip to content

Commit 9b498b4

Browse files
authored
Add extra validation to spritefont loader (#400)
1 parent c037a02 commit 9b498b4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Src/SpriteFont.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ SpriteFont::Impl::Impl(
156156
auto textureStride = reader->Read<uint32_t>();
157157
auto textureRows = reader->Read<uint32_t>();
158158

159+
if (!textureWidth
160+
|| !textureHeight
161+
|| !textureStride
162+
|| !textureRows
163+
|| (textureWidth > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION)
164+
|| (textureHeight > D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION)
165+
|| LoaderHelpers::BitsPerPixel(textureFormat) == 0)
166+
{
167+
DebugTrace("ERROR: SpriteFont provided with an invalid .spritefont file\n");
168+
throw std::runtime_error("Invalid .spritefont file");
169+
}
170+
159171
const uint64_t dataSize = uint64_t(textureStride) * uint64_t(textureRows);
160172
if (dataSize > UINT32_MAX)
161173
{

0 commit comments

Comments
 (0)