Skip to content

Commit 52b654c

Browse files
authored
Merge pull request #118 from OpenFodder/codex/propose-fix-for-vulnerability-in-asset-loading
Guard PC resource buffer accesses against truncated DAT files
2 parents ad2837d + d119270 commit 52b654c

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Source/Graphics.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ struct sImage {
7777
void LoadPalette(size_t pFrom, const size_t pCount, const size_t pStartColorID = 0) {
7878

7979
auto Buffer = mData->data();
80+
const size_t BufferSize = mData->size();
81+
const size_t PaletteBytes = pCount * 3;
82+
if (pFrom >= BufferSize || (BufferSize - pFrom) < PaletteBytes)
83+
return;
8084

8185
for (size_t ColorID = pStartColorID; ColorID < pStartColorID + pCount; ColorID++) {
8286

Source/PC/Graphics_PC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ void cGraphics_PC::Load_Hill_Data() {
203203

204204
// Parts of this surface have the recruits from mImageRecruit copied onto it
205205
mImageHillSprites = Decode_Image("hill.dat", 0x50, 0xFA00, 0x00);
206-
for (uint32 x = 0; x < 0xA000; ++x) {
206+
const uint32 ClearCount = std::min<uint32>(0xA000, mImageHillSprites.mData->size());
207+
for (uint32 x = 0; x < ClearCount; ++x) {
207208
mImageHillSprites.mData->data()[x] = 0;
208209
}
209210
}

0 commit comments

Comments
 (0)