Skip to content

Commit 8bd0376

Browse files
authored
Merge pull request #115 from OpenFodder/codex/propose-fix-for-amiga-iff-palette-vulnerability
Clamp Amiga palette copy size to destination capacity
2 parents d6f623b + ee8d7d3 commit 8bd0376

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Source/Amiga/Graphics_Amiga.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,11 @@ void cGraphics_Amiga::Load_And_Draw_Image(const std::string& pFilename, unsigned
391391
Decoded.mDimension.mHeight = 0x101;
392392
}
393393

394-
// Load the palette
395-
Decoded.CopyPalette(mPalette, (1LL << Decoded.mPlanes));
394+
// Load the palette (clamped to avoid overflow/UB from file-controlled plane counts)
395+
const size_t PaletteCapacity = sizeof(mPalette) / sizeof(mPalette[0]);
396+
const size_t PlaneCount = static_cast<size_t>(Decoded.mPlanes);
397+
const size_t RequestedColors = (PlaneCount < (sizeof(size_t) * 8)) ? (1ULL << PlaneCount) : PaletteCapacity;
398+
Decoded.CopyPalette(mPalette, std::min(RequestedColors, PaletteCapacity));
396399

397400
mBMHD_Current = Decoded.GetHeader();
398401

0 commit comments

Comments
 (0)