Repository navigation
Validate indexed BMP palette counts before reading - #105
Open
PS2HomeDeveloper wants to merge 1 commit into
Open
PS2HomeDeveloper wants to merge 1 commit into
PS2HomeDeveloper wants to merge 1 commit into
Conversation
## Summary `gsKit_texture_bmp` allocates fixed-size color lookup tables for 4-bpp and 8-bpp images, but uses the BMP header's `ColorUsed` value without checking it before reading palette data. A malformed file can therefore make `fread` write past the allocated CLUT. Validate indexed-color palette counts before allocating or reading the palette. Reject counts larger than `2^BitCount`, and interpret a zero count as the format-defined maximum for 4-bpp and 8-bpp BMPs. ## Testing - Build gsKit with the PS2 toolchain. - Verify that valid 4-bpp and 8-bpp BMPs with `ColorUsed` set to zero or the maximum palette size still load. - Verify that malformed 4-bpp (`ColorUsed = 17`) and 8-bpp (`ColorUsed = 257`) BMPs are rejected before palette data is read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gsKit_texture_bmpallocates fixed-size color lookup tables for 4-bpp and 8-bpp images, but uses the BMP header'sColorUsedvalue without checking it before reading palette data. A malformed file can therefore makefreadwrite past the allocated CLUT.Validate indexed-color palette counts before allocating or reading the palette. Reject counts larger than
2^BitCount, and interpret a zero count as the format-defined maximum for 4-bpp and 8-bpp BMPs.Testing
ColorUsedset to zero or the maximum palette size still load.ColorUsed = 17) and 8-bpp (ColorUsed = 257) BMPs are rejected before palette data is read.