CVE-2021-28021

7.8 HIGH

📋 TL;DR

This CVE describes a buffer overflow vulnerability in the stb_image.h library's JPEG parsing function. Attackers can exploit it by crafting a malicious JPEG file, potentially leading to arbitrary code execution. Any software using stb 2.26 or earlier versions of the stb_image library is affected.

💻 Affected Systems

Products:
  • Any software using stb_image.h library
Versions: stb 2.26 and earlier versions
Operating Systems: All operating systems where stb_image is used
Default Config Vulnerable: ⚠️ Yes
Notes: The vulnerability is in the library itself, so any application linking to vulnerable versions is affected regardless of configuration.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution with the privileges of the application processing the JPEG file, potentially leading to complete system compromise.

🟠

Likely Case

Application crash (denial of service) when processing malicious JPEG files, with potential for limited code execution depending on memory protections.

🟢

If Mitigated

Application crash with no code execution if modern security features like ASLR and DEP are properly implemented and enforced.

🌐 Internet-Facing: MEDIUM
🏢 Internal Only: LOW

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires the target to process a malicious JPEG file, which can be delivered via various vectors including web uploads, email attachments, or network shares.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: stb 2.27 and later

Vendor Advisory: https://github.com/nothings/stb/issues/1108

Restart Required: No

Instructions:

1. Update stb_image.h to version 2.27 or later. 2. Recompile any applications using the library. 3. Replace existing stb_image.h files with the patched version.

🔧 Temporary Workarounds

Disable JPEG processing

all

If possible, disable JPEG image processing in affected applications to prevent exploitation.

Input validation

all

Implement strict validation of JPEG files before processing, rejecting suspicious or malformed files.

🧯 If You Can't Patch

  • Implement application sandboxing to limit potential damage from exploitation
  • Use memory protection features like ASLR and DEP if not already enabled

🔍 How to Verify

Check if Vulnerable:

Check the version of stb_image.h in your codebase. If it's 2.26 or earlier, you are vulnerable.

Check Version:

grep -i "stb_image.h version" stb_image.h or check the file header comments

Verify Fix Applied:

Verify that stb_image.h has been updated to version 2.27 or later and that applications have been recompiled with the updated library.

📡 Detection & Monitoring

Log Indicators:

  • Application crashes when processing JPEG files
  • Memory access violation errors in application logs

Network Indicators:

  • Unusual JPEG file uploads to web applications
  • JPEG files with abnormal characteristics being transferred

SIEM Query:

source="application_logs" AND ("segmentation fault" OR "access violation" OR "buffer overflow") AND "jpeg"

🔗 References

📤 Share & Export