CVE-2026-42146 CImg Library: Uncontrolled memory allocation via nb_colors field in _load_bmp
Attackers can crash applications using CImg by providing crafted BMP files with large color counts, causing uncontrolled memory allocation.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Local or same network only
- Victim action needed
- A user has to click or open something
- Fix
- Available
What is CVE-2026-42146?
CVE-2026-42146 is a medium-severity denial of service vulnerability in GreycLab CImg, published on 4 May 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Official description
CImg Library is a C++ library for image processing. Prior to commit c3aacf5, the nb_colors field read from the BMP file header is used directly to compute an allocation size without validating it against the remaining file size. A crafted BMP file with a large nb_colors value triggers an out-of-memory condition, crashing any application that uses CImg to load untrusted BMP files. This issue has been patched via commit c3aacf5.
Weakness: CWE-789
Which versions are affected by CVE-2026-42146?
How do I fix CVE-2026-42146?
Apply the vendor's patch.
Upgrade, then put limits on request size, rate and nesting depth so one client cannot exhaust the service. More about Denial of service.
Is CVE-2026-42146 being exploited?
It is not confirmed as exploited in the wild, but public exploit code for CVE-2026-42146 exists.
Sources
Also known as DEBIAN-CVE-2026-42146, GHSA-g54r-qmgx-c6fv, UBUNTU-CVE-2026-42146.