Skip to content

Validate indexed BMP palette counts before reading - #105

Closed
PS2HomeDeveloper wants to merge 1 commit into
ps2dev:masterfrom
PS2HomeDeveloper:patch-1
Closed

PS2HomeDeveloper wants to merge 1 commit into
ps2dev:masterfrom
PS2HomeDeveloper:patch-1

Conversation

@PS2HomeDeveloper

Copy link
Copy Markdown

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.

## 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.
@PS2HomeDeveloper PS2HomeDeveloper closed this by deleting the head repository Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant