Skip to content

Fix bmp alloc dos#64

Open
Korolikc wants to merge 2 commits into
marc-q:masterfrom
Korolikc:fix-bmp-alloc-dos
Open

Fix bmp alloc dos#64
Korolikc wants to merge 2 commits into
marc-q:masterfrom
Korolikc:fix-bmp-alloc-dos

Conversation

@Korolikc
Copy link
Copy Markdown

Summary

This PR fixes a denial-of-service issue in bmp_img_alloc() where crafted BMP headers
can trigger excessive memory allocations leading to OOM/abort.

Root cause

  • bmp_img_alloc() performed allocations based on untrusted biWidth / biHeight
    without validating ranges or guarding against overflow.
  • Allocation failures were not propagated to callers.

Changes

  • Change bmp_img_alloc() to return enum bmp_error and validate dimensions:
    • Reject non-positive dimensions and INT_MIN height (abs overflow case)
    • Add SIZE_MAX overflow checks before allocation
    • Handle allocation failures and free partial allocations
  • bmp_img_read() now checks allocation result and exits gracefully on failure.
  • Remove meaningless abs() usage on unsigned indices.
  • Minor header indentation cleanup.

Verification

A minimized PoC BMP file previously triggered ASan OOM in bmp_img_alloc().
After this patch, the same PoC is rejected and the program exits normally
(no crash / abort).

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