Skip to content

Commit 84d9441

Browse files
fix: bounds checks for MaterialChunk shaderSize=0 and Ktx1Bundle constructor overflow
MaterialChunk::getTextShader: Add early return when shaderSize is 0 to prevent out-of-bounds write of null terminator at line 284. The bounds checks added in commit 92dc063 protect the loop body but not the unconditional null-terminator write after the loop. Ktx1Bundle 3-argument constructor: Add the same 64-bit overflow check that the deserialization constructor received in commit 16a7047. The multiplication numMipLevels * arrayLength * mNumCubeFaces can overflow uint32_t, causing sizes vector to be undersized. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e8b268b commit 84d9441

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

libs/filaflat/src/MaterialChunk.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ bool MaterialChunk::getTextShader(Unflattener unflattener,
186186
if (!unflattener.read(&shaderSize)){
187187
return false;
188188
}
189+
if (shaderSize == 0) {
190+
return false;
191+
}
189192

190193
// Read how many lines there are.
191194
uint32_t lineCount = 0;

libs/image/src/Ktx1Bundle.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ Ktx1Bundle::Ktx1Bundle(uint32_t numMipLevels, uint32_t arrayLength, bool isCubem
106106
mNumMipLevels = numMipLevels;
107107
mArrayLength = arrayLength;
108108
mNumCubeFaces = isCubemap ? 6 : 1;
109-
mBlobs->sizes.resize(numMipLevels * arrayLength * mNumCubeFaces);
109+
uint64_t const totalBlobs = (uint64_t)numMipLevels * arrayLength * mNumCubeFaces;
110+
FILAMENT_CHECK_POSTCONDITION(totalBlobs <= (uint64_t)std::numeric_limits<uint32_t>::max())
111+
<< "KTX dimensions overflow";
112+
mBlobs->sizes.resize((uint32_t)totalBlobs);
110113
}
111114

112115
Ktx1Bundle::Ktx1Bundle(uint8_t const* bytes, uint32_t nbytes) :

0 commit comments

Comments
 (0)