CVE-2026-21413
Executive Summary
CVE-2026-21413 is a critical heap-based buffer overflow vulnerability in the lossless_jpeg_load_raw functionality of LibRaw, a widely used open-source library for decoding raw camera image formats (CR2, NEF, DNG, etc.). Affected versions include builds incorporating commit 0b56545 up to commit d20315b (unfixed). The flaw is triggered by a specially crafted malicious image file, leading to memory corruption that an attacker can leverage for arbitrary code execution or denial of service. With a CVSS base score of 9.8 (Critical), the vulnerability poses a severe risk to any application, service, or appliance that processes untrusted raw image files, including web upload portals, email gateways, and digital forensics tools. No public exploit code exists at the time of writing, but the technical simplicity of the flaw class (heap overflow in a parser) makes exploitation feasible for skilled attackers.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Technical Analysis
The vulnerability resides in the lossless_jpeg_load_raw function within LibRaw's internal decoder for lossless JPEG-compressed raw sensor data. This code path is used when parsing raw formats that employ lossless JPEG (e.g., certain Samsung SRW, Kodak DCR, and some DNG variants).
Vulnerable mechanism: The function reads a stream of JPEG-encoded coefficients and tracks a running offset into a destination buffer (imgdata.rawdata.raw_image) that holds the decompressed pixel data. A flaw exists in the bounds checking when processing restart markers and coefficient run-lengths: the code fails to validate that the computed write offset (row * width + col) stays within the allocated heap buffer that was sized based on the image metadata contained in the file header. An attacker crafts a file where the declared dimensions (width/height) in the raw header are small, but the embedded JPEG stream contains more coefficient data than the buffer can hold, or where negative/overflowed offsets are computed via integer wrap, causing writes past the heap chunk.
Code-level detail: In the reference commits, the vulnerable logic resembles:
int lossless_jpeg_load_raw(...) {
// ...
while (....) {
// decode Huffman coefficient
// ...
imgdata.rawdata.raw_image[(row * imgdata.sizes.width) + col] = value;
// ^ no bounds check that row*width+col < raw_image_size
col++;
if (col >= imgdata.sizes.width) { col = 0; row++; }
}
}
Because imgdata.sizes.width is attacker-controlled from the file header and the buffer size is allocated as width * height * sizeof(ushort), a mismatch between the declared width and the actual number of pixels decoded per row (or an integer overflow in row * width) allows out-of-bounds writes.
Attack surface: The primary vector is file-based: any process that calls LibRaw::open_buffer(), LibRaw::unpack(), or libraw_openfile() on user-supplied files. This includes:
- Web applications with image upload (e.g., photo sharing, CMS with EXIF/RAW preview generation).
- Email gateways that thumbnail attachments.
- Desktop apps: Photoshop plugins, RawTherapee, darktable.
- Forensic tools and antivirus engines that parse raw files.
The vulnerability is trivially reachable over the network if an attacker can upload or email a malicious file. No authentication is required if the target exposes a file-processing endpoint.
Exploitation Scenarios
Step-by-step attack chain:
Reconnaissance/identification: The attacker identifies a web application or service that accepts raw image uploads and processes them with LibRaw. They may fingerprint this by uploading a small valid RAW file and observing if thumbnail generation or metadata extraction occurs. Application error messages or server headers (e.g.,
X-Powered-By: PHPwithImagick/librawbackend) may also reveal the library. For desktop targets, the attacker could craft a malicious file that is distributed via spear-phishing.Weaponization/trigger:
- The attacker downloads a valid raw file from a camera (e.g., Samsung .srw file).
- Using a hex editor or custom script, they modify the raw header to declare a small width (e.g.,
width=10) while keeping the height large (e.g.,height=5000). - They then craft the embedded lossless JPEG stream to contain a long run of high-frequency coefficients exceeding
10 * 5000entries. The decoder will write pixels sequentially into a buffer allocated for10 * 5000 * 2bytes, but the crafted stream causes the loop to continue writing past the buffer end. - Alternative: induce integer overflow by setting width near
0xFFFFand height such thatwidth * heightwraps to a small positive number — the allocation is tiny, but the decoder writes sequentially for many rows.
Payload/execution: The heap overflow corrupts adjacent heap metadata. The attacker arranges the heap layout beforehand (heap feng shui) using prefix allocations via multiple image uploads in the same process (e.g., session-based PHP workers or long-running daemons). They overwrite a function pointer or a
sizefield of an adjacent chunk to gain arbitrary write, then leverage it to execute shellcode (e.g.,execve("/bin/sh")in a CLI context, or a reverse shell in a web worker). Alternate: simpler DoS by corrupting the heap chunk size to trigger an assertion/abort onfree().Post-exploitation: With code execution as the service account (e.g.,
www-data), the attacker:- Exfiltrates secrets from the web server (database credentials, API keys).
- Escalates privileges via local kernel exploits or misconfigured sudo.
- Pivots laterally into the internal network using installed SSH keys or cloud metadata APIs (if in cloud environment, retrieves IAM credentials from
169.254.169.254).
Realistic scenario: A popular image upload service (e.g., a stock photo site) allows users to upload RAW files for automatic preview generation. The attacker uploads a .srw file modified as described. The server-side worker process crashes or executes the payload, giving the attacker a foothold.
Impact Assessment
Security impact (CVSS breakdown): Base score 9.8 (Critical). Vector: AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
- Confidentiality (High): Successful exploitation leads to arbitrary code execution, full disclosure of server memory and files.
- Integrity (High): Attacker can modify files, plant backdoors, or alter data.
- Availability (High): Easy crash potential (heap corruption), plus full DoS via CPU exhaustion or system takeover.
Business impact: For organizations relying on LibRaw:
- Production web applications that process images are directly exposed to remote code execution (RCE) with zero authentication.
- Media and publishing industries — content management systems that ingest camera files are compromised.
- Forensics/legal — tampered evidence files could execute malicious code, compromising chain-of-custody systems.
Blast radius: Any system where LibRaw is linked statically or dynamically. Because the library is present in Linux distributions (Debian, Ubuntu, Fedora), macOS (via Homebrew), and is embedded in many third-party applications, the affected population is extensive. The EPSS score of 0.00746 (51.3rd percentile) indicates the vulnerability is not yet actively exploited but is within the range where exploitation is expected as public awareness grows.
Detection Guidance
Detection is challenging because the flaw is triggered during local file parsing, not via a distinct network signature. However, monitoring file bytes and process behavior can identify attempts.
Sigma Rule
title: LibRaw Heap Overflow Trigger via Malicious RAW Header
id: 9b0e1f2a-3c4d-5e6f-8a9b-0c1d2e3f4a5b
status: experimental
description: Detects processes loading LibRaw that process a file with mismatched dimensions indicating crafted raw image.
logsource:
category: process_creation
product: linux
detection:
selection:
Image|endswith:
- '/rawtherapee'
- '/darktable'
- '/convert'
- '/php'
filter:
CommandLine|contains: 'raw'
condition: selection and filter
level: high
tags:
- attack.t1203
- cve.2026.21413
Note: The above rule is intentionally high-level; more precise detection is file-content-based. The realistic Sigma rule should be:
title: Suspicious RAW File with Fragmented Lossless JPEG
id: 7d3f1c9a-2b4e-4f8a-9c1d-5e6f7a8b9c0d
status: experimental
description: Detects file writes or reads of raw image files where the JPEG stream length exceeds expected size.
logsource:
category: file_event
product: linux
detection:
selection:
TargetFilename|endswith: ['.srw', '.dng', '.cr2', '.nef']
condition: selection
level: medium
tags:
- attack.t1203
- cve.2026.21413
YARA Rule
rule CVE_2026_21413_LibRaw_Heap_Overflow {
meta:
author = "Valters IT SOC"
description = "Detects malformed lossless JPEG raw files exploiting LibRaw buffer overflow"
reference = "CVE-2026-21413"
date = "2026-01-15"
strings:
$srw_magic = { 53 52 57 20 } // "SRW "
$dng_magic = { 49 49 2A 00 } // little-endian TIFF header
$jpeg_stream = { FF D8 FF C4 } // JPEG SOI + DHT
$small_width = { ?? ?? 0A 00 } // width field = 10 (example)
condition:
($srw_magic or $dng_magic) and $jpeg_stream and #small_width > 0 and filesize > 100KB
}
Suricata IDS Rule
alert http any any -> any any (msg:"CVE-2026-21413 LibRaw Heap Overflow - Malicious RAW Image Upload"; flow:to_server; file.data; content:"SRW"; offset:0; depth:4; content:"|ff d8 ff c4|"; within:4096; detection_filter:track by_src, count 1, seconds 60; classtype:attempted-admin; sid:202621413; rev:1;)
Note: This rule detects network transfer of a suspicious .srw file containing a JPEG stream. False positives are possible (legitimate raw files contain JPEG). Tune with threshold and inspect file.size if available.
Elastic Detection
`any where process.name == "rawtherapee" or process.name == "darktable" or process.name == "libraw_demo"`
`api-key`: "cve-2026-21413-detection"
More realistic EQL:
file where event.action == "open" and file.extension in ("srw", "dng", "cr2", "nef") and process.name == "libraw_demo"
For host-level:
process where process.name == "libraw_demo" and process.args_count > 5 and process.args == "*.srw"
Splunk SPL Query
index=windows OR index=linux sourcetype=WinEventLog:Security OR sourcetype=linux_audit
| search (Image="*rawtherapee*" OR Image="*darktable*" OR Image="*libraw*")
| regex CommandLine="(?i).*\.(srw|dng|cr2|nef)"
| eval dc=sha256(CommandLine)
| stats count values(CommandLine) by Image, dest
| where count > 10
Wazuh OSSEC Rule
<group name="libraw_overflow,">
<rule id="100214" level="12">
<if_sid>5715</if_sid>
<field name="file.name">\.(srw|dng|cr2|nef)$</field>
<description>CVE-2026-21413: File with suspicious raw extension opened by image processing</description>
<group>attack.t1203,</group>
<mitre>
<id>T1203</id>
</mitre>
</rule>
</group>
Mitigation & Patch Guidance
Patch confidence: 3/4 (LIKELY). Two independent sources (OSV and Debian) confirm the fix exists in a later commit. The vendor (LibRaw) has not published a formal advisory via NVD, but the fix is present in their git repository.
Immediate mitigation (no patch applied yet):
- Restrict file uploads: If you operate a web service, disable support for raw camera formats (
.srw,.cr2,.nef,.dng) at the application layer until patched. Convert to a safe format client-side before upload. - Isolate processing: Run LibRaw in a sandboxed container (Docker with no network, seccomp profile) or a dedicated low-privilege user with no access to other parts of the system.
- Use a wrapper: Implement a file validation script that parses the raw header before passing it to LibRaw. If declared width*height > 10 million pixels, reject the file (possible abuser).
- Restrict file uploads: If you operate a web service, disable support for raw camera formats (
Patch/upgrade steps:
- Linux distros: Debian/Ubuntu users should run
apt update && apt upgrade libraw*. Fedora/RHEL:dnf update libraw. Check your distro's security tracker for the exact fixed version number. - From source: For custom integrations, pull the latest LibRaw master branch (commit newer than
d20315b) and rebuild:git clone https://github.com/LibRaw/LibRaw.git && cd LibRaw && autoreconf -fi && ./configure && make && make install. - Windows/macOS: Update binary packages from the vendor that bundles LibRaw (e.g., RawTherapee, darktable). Reinstall the latest versions of those applications.
- Linux distros: Debian/Ubuntu users should run
Long-term hardening:
- Memory safety: Compile LibRaw with address sanitizers (
-fsanitize=address) in development CI to catch future heap overflows. - Process hardening: Enable ASLR and DEP system-wide; run image processors under
systemdwithMemoryDenyWriteExecute=true. - Monitoring: Implement the detection rules above in your SIEM/EDR. Add file integrity monitoring on directories that accept uploads.
- Library upgrades: Subscribe to LibRaw's security mailing list and the OSV database (
osv.dev) for automated CVE alerts.
- Memory safety: Compile LibRaw with address sanitizers (
References
- NVD Entry: https://nvd.nist.gov/vuln/detail/CVE-2026-21413 — Official record, CVSS score and description.
- OSV Advisory: https://osv.dev/vulnerability/CVE-2026-21413 — Commit-level affected range (
0b56545...d20315b) with patch status. - Debian Security Tracker: https://security-tracker.debian.org/tracker/CVE-2026-21413 — Confirms fix in Debian package version.
- LibRaw GitHub Repository: https://github.com/LibRaw/LibRaw — Source code, commit history for fix retrieval.
- MITRE ATT&CK: https://attack.mitre.org/techniques/T1203/ — Client-Side Execution tactic reference.
Threat actor campaigns: As of this writing, there is no evidence of exploitation in the wild. The vulnerability was disclosed via coordinated responsible disclosure (CNA: Talos), and the 51.3rd percentile EPSS rank indicates low immediate exploitation likelihood. However, given the critical severity and the simplicity of crafting a malformed file, this is expected to change within 30-60 days post-disclosure as script-kiddie tools are built.
What is this? Security researchers use these exact search queries on Shodan.io (a search engine for internet-connected devices) to find vulnerable systems globally. You can copy these dorks to see if your organization's IP space is exposed.
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.