Skip to content

bmp: reject images exceeding 128 megapixels on 64-bit platforms#33

Closed
herdiyana256 wants to merge 1 commit into
golang:masterfrom
herdiyana256:fix/bmp-memory-exhaustion-64bit
Closed

bmp: reject images exceeding 128 megapixels on 64-bit platforms#33
herdiyana256 wants to merge 1 commit into
golang:masterfrom
herdiyana256:fix/bmp-memory-exhaustion-64bit

Conversation

@herdiyana256

@herdiyana256 herdiyana256 commented Jun 17, 2026

Copy link
Copy Markdown

Fix incomplete memory exhaustion guard in the BMP decoder for 64-bit
platforms.

The safemath.Mul3 check added in CL 787680 prevents integer overflow
but does not cap large-but-valid allocations on 64-bit systems. A
16384x16384 image at 32bpp passes the overflow check and causes a
1 GB allocation in image.NewNRGBA before any pixel data is read.

Add a pixel-count limit of 1<<27 (128 megapixels) consistent with
the TIFF decoder fix for CVE-2026-33809.

A regression test verifies the 54-byte attack file is rejected
without triggering the allocation.

Fixes golang/go#80169

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 6962467) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/image/+/791840.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@herdiyana256 herdiyana256 force-pushed the fix/bmp-memory-exhaustion-64bit branch from 6962467 to 7329e92 Compare June 18, 2026 15:32
The safemath.Mul3 check added in CL 787680 prevents integer overflow
but does not cap large-but-valid allocations on 64-bit systems. For
a 16384x16384 image at 32bpp, the multiplication does not overflow
int64, so the check passes and image.NewNRGBA allocates 1 GB before
returning an EOF error. Under concurrent load, this exhausts memory
before the garbage collector can reclaim it.

Add a pixel-count limit of 1<<27 (128 megapixels) consistent with
the TIFF decoder fix for CVE-2026-33809.

A regression test verifies the 54-byte attack file from the report
is rejected without triggering the allocation.
@herdiyana256 herdiyana256 force-pushed the fix/bmp-memory-exhaustion-64bit branch from 7329e92 to a79343f Compare June 18, 2026 15:36
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: a79343f) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/image/+/791840.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from herdiyanitdev:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from herdiyanitdev:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Jorropo:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from herdiyanitdev:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from herdiyanitdev:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/791840.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

This PR is being closed because golang.org/cl/791840 has been abandoned.

golang/go#80169 (comment)

@gopherbot gopherbot closed this Jun 26, 2026
@herdiyana256

Copy link
Copy Markdown
Author

Closing this PR as the Go team has determined this is intended behavior per the Security Considerations documentation. Damien Neil abandoned the corresponding CL 791840 and closed golang/go#80169 as not planned.

Thanks for the review.

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.

x/image/bmp: large BMP dimensions cause ~1 GB allocation on 64-bit platforms

2 participants