Cloudanix VulnDB

CVE-2021-42716

High · 7.1

CVSS

7.1

EPSS

1.5%

Published

Oct 21, 2021

CISA due date

—

Cloudanix analysis

Schedule a fix SSVC: Track

A flaw in a popular image library can let attackers crash programs or peek at small pieces of memory by sending a specially made picture file.

Exploit Available
Exploitation
Requires User Interaction
Attacker needs
User Interaction
Complexity
Low
Impact
Data Exposure
Component
Library
Class
Buffer Overflow
Remediation
Upgrade
Effort
Medium
Patch risk
Low

What it actually does

The PNM loader in stb_image.h misinterprets 16-bit PGM files as 8-bit during RGBA conversion, causing a buffer overflow on subsequent reinterpretation as a 16-bit buffer that enables service crashes or up to 1024 bytes of non-consecutive heap reads.

Why it matters to the business

Applications processing untrusted image files risk denial of service through crashes or limited unauthorized data exposure, with elevated urgency due to public exploit availability more than five years after disclosure and no vendor fixes listed.

How an attack unfolds

An attacker crafts a malicious 16-bit PGM image file that triggers incorrect bit-depth handling in the PNM loader; when an affected application opens the file the overflow occurs, allowing either a crash or partial heap memory disclosure without attacker control over read locations.

How to fix it

Upgrade stb_image.h to a version later than 2.27 that corrects the PNM 16-bit handling logic; rebuild and redeploy all dependent applications; where direct upgrades are unavailable apply vendor patches for Fedora or equivalent downstream distributions.

How to confirm the fix worked

Confirm stb_image.h version exceeds 2.27, execute unit tests using both valid and malformed 16-bit PGM samples, and verify that RGBA conversion no longer produces oversized buffers or memory reads.

Typical attack path

  1. Craft a specially malformed 16-bit PGM file that exploits the bit-depth misinterpretation
  2. Deliver the file to a target application that uses stb_image for image loading
  3. Trigger file parsing through normal application workflows such as preview or import
  4. Observe resulting crash or collect disclosed heap contents

How to detect it

Review application logs and crash dumps for segmentation faults during PNM or PGM image loading; inspect heap memory artifacts around image buffer allocations for unexpected 16-bit versus 8-bit size mismatches.

What your security team should do

  • Prioritize inventory of all products embedding stb_image.h and schedule immediate library replacement
  • Implement file-type validation and sandboxing for image processing workflows until patches are applied
  • Monitor public exploit repositories given the ExploitAvailable maturity rating

The record

An issue was discovered in stb stb_image.h 2.27. The PNM loader incorrectly interpreted 16-bit PGM files as 8-bit when converting to RGBA, leading to a buffer overflow when later reinterpreting the result as a 16-bit buffer. An attacker could potentially have crashed a service using stb_image, or read up to 1024 bytes of non-consecutive heap data without control over the read location.

Affected packages

Ecosystem Package Introduced Fixed
Debian:12 libstb 0 No fix
Debian:13 libstb 0 0.0~git20230129.5736b15+ds-1
Mageia:8 curaengine 0 4.8.0-1.1.mga8
Mageia:8 zxing-cpp 0 1.1.1-2.1.mga8
SUSE:Linux Enterprise Module for Package Hub 15 SP3 zxing-cpp 0 1.2.0-9.7.1
SUSE:Linux Enterprise Software Development Kit 12 SP5 zxing-cpp 0 1.2.0-8.6.1
SUSE:Linux Enterprise Workstation Extension 12 SP5 zxing-cpp 0 1.2.0-8.6.1
SUSE:Linux Enterprise Workstation Extension 15 SP3 zxing-cpp 0 1.2.0-9.7.1
SUSE:Package Hub 15 SP3 stb 0 2.32.1549563867.59e9702-bp153.2.3.1
Ubuntu:20.04:LTS libstb 0 No fix
Ubuntu:22.04:LTS libstb 0 No fix
Ubuntu:24.04:LTS libstb 0 No fix
Ubuntu:24.10 libstb 0 No fix
Ubuntu:25.04 libstb 0 No fix
Ubuntu:25.10 libstb 0 No fix
Ubuntu:Pro:20.04:LTS libstb 0 No fix
openSUSE:Leap 15.3 stb 0 2.32.1549563867.59e9702-bp153.2.3.1
openSUSE:Leap 15.3 zxing-cpp 0 1.2.0-9.7.1

Related vulnerabilities