Skip to content

Commit 6bfda20

Browse files
authored
Add extra validation to spritefont loader (#628)
1 parent ef1bd5d commit 6bfda20

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
@@ -142,6 +142,18 @@ SpriteFont::Impl::Impl(
142142
auto textureStride = reader->Read<uint32_t>();
143143
auto textureRows = reader->Read<uint32_t>();
144144

145+
if (!textureWidth
146+
|| !textureHeight
147+
|| !textureStride
148+
|| !textureRows
149+
|| (textureWidth > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)
150+
|| (textureHeight > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)
151+
|| LoaderHelpers::BitsPerPixel(textureFormat) == 0)
152+
{
153+
DebugTrace("ERROR: SpriteFont provided with an invalid .spritefont file\n");
154+
throw std::runtime_error("Invalid .spritefont file");
155+
}
156+
145157
const uint64_t dataSize = uint64_t(textureStride) * uint64_t(textureRows);
146158
if (dataSize > UINT32_MAX)
147159
{

0 commit comments

Comments
 (0)