CTexture bounds validation

This commit is contained in:
Jack Andersen 2016-09-02 19:19:22 -10:00
parent ce3014b313
commit 2dbb06f8b1
3 changed files with 15 additions and 8 deletions

View File

@ -35,8 +35,8 @@ class CTexture
void BuildRGB5A3FromGCN(CInputStream& in); void BuildRGB5A3FromGCN(CInputStream& in);
void BuildRGBA8FromGCN(CInputStream& in); void BuildRGBA8FromGCN(CInputStream& in);
void BuildDXT1FromGCN(CInputStream& in); void BuildDXT1FromGCN(CInputStream& in);
void BuildRGBA8(const void* data); void BuildRGBA8(const void* data, size_t length);
void BuildC8(const void* data); void BuildC8(const void* data, size_t length);
public: public:
CTexture(std::unique_ptr<u8[]>&& in, u32 length); CTexture(std::unique_ptr<u8[]>&& in, u32 length);

View File

@ -648,21 +648,28 @@ void CTexture::BuildDXT1FromGCN(CInputStream& in)
}); });
} }
void CTexture::BuildRGBA8(const void* data) void CTexture::BuildRGBA8(const void* data, size_t length)
{ {
size_t texelCount = ComputeMippedTexelCount(); size_t texelCount = ComputeMippedTexelCount();
size_t expectedSize = texelCount * 4;
if (expectedSize > length)
Log.report(logvisor::Fatal, "insufficient TXTR length (%" PRISize "/%" PRISize ")",
length, expectedSize);
m_booToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool m_booToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{ {
m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8, m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8,
data, texelCount * 4); data, expectedSize);
return true; return true;
}); });
} }
void CTexture::BuildC8(const void* data) void CTexture::BuildC8(const void* data, size_t length)
{ {
size_t texelCount = ComputeMippedTexelCount(); size_t texelCount = ComputeMippedTexelCount();
if (texelCount > length)
Log.report(logvisor::Fatal, "insufficient TXTR length (%" PRISize "/%" PRISize ")",
length, texelCount);
m_booToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool m_booToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{ {
@ -722,10 +729,10 @@ CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length)
BuildDXT1FromGCN(r); BuildDXT1FromGCN(r);
break; break;
case ETexelFormat::RGBA8PC: case ETexelFormat::RGBA8PC:
BuildRGBA8(owned.get() + 12); BuildRGBA8(owned.get() + 12, length - 12);
break; break;
case ETexelFormat::C8PC: case ETexelFormat::C8PC:
BuildC8(owned.get() + 12); BuildC8(owned.get() + 12, length - 12);
break; break;
default: default:
Log.report(logvisor::Fatal, "invalid texture type %d for boo", int(x0_fmt)); Log.report(logvisor::Fatal, "invalid texture type %d for boo", int(x0_fmt));

2
hecl

@ -1 +1 @@
Subproject commit 172d1de275d05f1fc8d69dac0c193d7c8bcc78cd Subproject commit 42679f2a3ae651a7c070688969a8a8430791256e