Skip to content

reject undecodable bmp bit depths in ParseHeader#421

Merged
ermig1979 merged 1 commit into
ermig1979:masterfrom
metsw24-max:bmp-reject-undecodable-depth
Jun 13, 2026
Merged

reject undecodable bmp bit depths in ParseHeader#421
ermig1979 merged 1 commit into
ermig1979:masterfrom
metsw24-max:bmp-reject-undecodable-depth

Conversation

@metsw24-max

Copy link
Copy Markdown
Contributor

Heap overflow on undecodable BMP bit depths
For any depth other than 8 or 24 ParseHeader sets channels to 4, so a 16-bit BMP (accepted by both the BITFIELDS and the uncompressed paths) ends up with _size = _width * 4 while the bit-field masks it parses are never applied and no converter exists for it. FromStream then copies _width * 4 bytes per row into a destination sized for the requested Gray8/Bgr24 output and runs past the image allocation, so rejecting the depths the loader cannot actually decode in ParseHeader looks like the least invasive place to stop it. Proper 16-bit handling could be added later as a separate change.

@ermig1979 ermig1979 merged commit c8b99eb into ermig1979:master Jun 13, 2026
26 checks passed
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.

2 participants