CVE-2024-41311
Executive Summary
CVE-2024-41311 is a critical memory safety vulnerability in Libheif version 1.17.6, specifically within the ImageOverlay::parse() function. The flaw arises from insufficient validation of offset values when decoding a HEIF file containing an overlay image. An attacker can craft a malicious HEIF file with forged offsets, leading to an out-of-bounds (OOB) read and write condition. This can result in memory corruption, potential code execution, or denial of service. The vulnerability has a CVSS score of 0.0 (placeholder) and an EPSS score of 0.0%, indicating low exploitation probability at this time, but the technical severity is high due to the nature of OOB access. No public proof-of-concept (PoC) or patch is currently available.
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
Supply Chain & Package Security
Libheif is a widely used library for handling HEIF/HEIC image formats, commonly integrated into image processing tools, media players, and web applications. This vulnerability affects any software that uses the vulnerable version of Libheif (1.17.6) to parse HEIF files with overlay images. The lack of a patch increases supply chain risk, as downstream consumers must rely on workarounds or wait for an official fix.
CVSS Breakdown & Threat Level
- CVSS Score: 0.0 (placeholder – actual score pending NVD analysis)
- Attack Vector (AV): Local (requires user to open a malicious file)
- Attack Complexity (AC): Low
- Privileges Required (PR): None
- User Interaction (UI): Required (user must open the file)
- Scope (S): Unchanged
- Confidentiality (C): High (OOB read can leak memory)
- Integrity (I): High (OOB write can corrupt memory)
- Availability (A): High (can cause crash or code execution)
- Threat Level: High (due to potential for code execution and memory corruption)
Deep Dive & Mechanics
The vulnerability resides in the ImageOverlay::parse() method of Libheif 1.17.6. When parsing a HEIF file that contains an overlay image, the function reads offset values from the file structure without proper bounds checking. These offsets are used to calculate memory addresses for reading and writing pixel data. By providing forged offset values, an attacker can cause the function to access memory outside the allocated buffer, leading to:
- Out-of-bounds read: Leak sensitive information from adjacent memory regions.
- Out-of-bounds write: Overwrite critical data structures, potentially leading to arbitrary code execution.
The root cause is the lack of validation that the computed memory address falls within the bounds of the allocated buffer for the overlay image. This is a classic memory corruption vulnerability common in C/C++ libraries.
Vulnerable vs. Patched Code
Vulnerable Code (Libheif 1.17.6):
// Simplified vulnerable code in ImageOverlay::parse()
void ImageOverlay::parse(StreamReader& reader) {
// ... read overlay offsets from file
int offset_x = reader.read32(); // no bounds check
int offset_y = reader.read32(); // no bounds check
// ... use offsets to access pixel data
uint8_t* pixel_data = buffer + offset_y * stride + offset_x;
// OOB access if offsets are forged
}
Patched Code (Hypothetical fix):
// Patched version with bounds checking
void ImageOverlay::parse(StreamReader& reader) {
int offset_x = reader.read32();
int offset_y = reader.read32();
// Validate offsets against buffer dimensions
if (offset_x < 0 || offset_x >= width || offset_y < 0 || offset_y >= height) {
throw std::runtime_error("Invalid overlay offset");
}
uint8_t* pixel_data = buffer + offset_y * stride + offset_x;
// Safe access
}
Exploitation & Lab Setup
Red Team
Lab Setup:
- Install Libheif 1.17.6 on a test system (e.g., Ubuntu 22.04).
- Create a malicious HEIF file with forged overlay offsets using a hex editor or custom script.
- Use a tool like
heif-convertor a custom application that callsImageOverlay::parse()to trigger the vulnerability.
Exploitation Steps:
- Craft a HEIF file with an overlay image item containing offset values that point outside the allocated buffer.
- Deliver the file to the target (e.g., via email, web download).
- When the target opens the file with a vulnerable application, the OOB write can corrupt memory, potentially leading to code execution.
Note: No public exploit code is available. The following is a conceptual example of a malicious HEIF structure:
# Conceptual Python script to generate a malicious HEIF file
import struct
def create_malicious_heif():
# Simplified HEIF structure with forged overlay offsets
ftyp = b'ftypheic' # File type box
meta = b'meta' # Metadata box
# Overlay item with forged offsets (e.g., offset_x = 0xFFFFFFFF, offset_y = 0xFFFFFFFF)
overlay_data = struct.pack('<II', 0xFFFFFFFF, 0xFFFFFFFF) # Forged offsets
# ... build full HEIF file
return ftyp + meta + overlay_data
with open('malicious.heic', 'wb') as f:
f.write(create_malicious_heif())
Blue Team
Detection:
- Monitor for crashes or abnormal memory access patterns in applications using Libheif.
- Use memory protection mechanisms (ASLR, DEP) to mitigate exploitation.
- Implement file scanning for HEIF files with suspicious overlay offsets.
Hunting:
- Search for logs containing "ImageOverlay::parse" or "heif" errors.
- Analyze network traffic for HEIF file downloads from untrusted sources.
Indicators of Compromise (IOCs)
- File Hashes (SHA256): (None available – placeholder)
- Network Indicators: HEIF files with unusual overlay offsets (e.g., extremely large or negative values).
- Behavioral Indicators: Application crashes or memory corruption errors when processing HEIF files.
- Registry/File System: Temporary files created by vulnerable applications during HEIF parsing.
Detection Engineering
YARA Rule
rule CVE_2024_41311_Libheif_OOB {
meta:
description = "Detects malicious HEIF files exploiting CVE-2024-41311"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2024-41311"
strings:
$heif_magic = { 66 74 79 70 68 65 69 63 } // "ftypheic"
$overlay_offset = { FF FF FF FF FF FF FF FF } // Forged offset pattern
condition:
$heif_magic and $overlay_offset
}
Sigma Rule
title: CVE-2024-41311 Libheif Out-of-Bounds Access
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects potential exploitation of CVE-2024-41311 via application crashes
author: Valters IT
date: 2025-04-10
logsource:
category: application
product: libheif
detection:
selection:
EventID: 1000 # Application crash event
Image: '*heif*'
ExceptionCode: 0xc0000005 # Access violation
condition: selection
falsepositives:
- Legitimate crashes due to other bugs
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-41311 - Malicious HEIF File Download"; flow:to_client; file.data; content:"ftypheic"; offset:0; depth:8; content:"|FF FF FF FF FF FF FF FF|"; within:100; classtype:attempted-user; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate: Disable processing of HEIF overlay images in applications using Libheif 1.17.6 until a patch is available.
- Patch: Monitor the Libheif project for an official fix (expected in a future release). Apply the patch as soon as it is released.
- Workaround: Use input validation to reject HEIF files with suspicious overlay offsets (e.g., offsets exceeding image dimensions).
- Long-term: Implement fuzz testing for HEIF parsing code to catch similar vulnerabilities.
Valters IT – DevSecOps & Cyber Threat Intelligence Expert