Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2025-66628 — Technical analysis of CVE-2025-66628, an integer overflow in ImageMagick's TIM parser leading to out-of-bounds reads, with root cause, exploitation steps, and remediation guidance. | Kitploit
Tools/GitHubGitHub/sumitshah00/cve-2025-66628
Static AnalysisVulnerability AnalysisCode AnalysisExploitationBinary AnalysisPapers & ResearchLearning & Education
GitHubsumitshah00/cve-2025-66628

CVE-2025-66628

Technical analysis of CVE-2025-66628, an integer overflow in ImageMagick's TIM parser leading to out-of-bounds reads, with root cause, exploitation steps, and remediation guidance.

View Repository
129 months agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

CVE-2025-66628: Integer Overflow in ImageMagick TIM Parser

AttributeDetails
CVE IDCVE-2025-66628
VendorImageMagick Studio LLC
ProductImageMagick
Affected Versions< 7.1.2-10
Fixed Version7.1.2-10
Vulnerability TypeCWE-190 (Integer Overflow)
CVSS v3.1 Score7.5 (High)
CVSS VectorCVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
ResearcherSumit Shah

Summary

An integer overflow vulnerability exists in the ReadTIMImage function within coders/tim.c of ImageMagick. When processing TIM (PlayStation) image files on 32-bit systems, unchecked multiplication of user-controlled width and height values results in memory under-allocation, leading to out-of-bounds reads during pixel processing.


Technical Details

Affected Code

The vulnerable logic resides in coders/tim.c:

root@kitploit:~
/* coders/tim.c - TIM Image Parser */

// User-controlled input from TIM file header
width = ReadBlobLSBShort(image);   // 2 bytes (0-65535)
height = ReadBlobLSBShort(image);  // 2 bytes (0-65535)

// VULNERABLE: Integer overflow on 32-bit systems
image_size = 2 * width * height;  // No overflow check

// Memory allocated with truncated size
pixels = (unsigned char *) AcquireQuantumMemory(image_size, sizeof(*pixels));

// Loop processes FULL dimensions, reading beyond buffer
for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
        pixel_index = (y * width + x) * 2;
        pixels[pixel_index] = ReadBlobByte(image);
        pixels[pixel_index + 1] = ReadBlobByte(image);
    }
}

Root Cause

On 32-bit architectures, size_t is limited to 32 bits with maximum value UINT_MAX = 4,294,967,295.

When width and height are both set to maximum 16-bit unsigned values:

root@kitploit:~
width = 65535 (0xFFFF)
height = 65535 (0xFFFF)

Expected calculation:
2 × 65535 × 65535 = 8,589,869,050 bytes (~8.5 GB)

Actual result (32-bit wraparound):
8,589,869,050 % 4,294,967,296 = 4,294,901,754
Result after truncation: Small allocated buffer

The overflow causes the memory allocator to reserve a drastically smaller buffer than required, while the processing loop still iterates over the full 65535 × 65535 pixel grid, resulting in out-of-bounds reads.

Exploitation

Step 1: Attacker crafts TIM file with dimensions causing overflow

root@kitploit:~
[Magic: 0x10]
[Type: 0x02]
[Width: 0xFFFF]   # 65535
[Height: 0xFFFF]  # 65535
[Pixel Data...]

Step 2: Victim processes the malicious file

root@kitploit:~
convert malicious.tim output.png

Step 3: Out-of-bounds read occurs, leading to:

  • Heap memory disclosure (leaked into output image or observable via timing)
  • Segmentation fault (denial of service)

Affected Platforms

32-bit systems where size_t is 32-bit. 64-bit systems are not affected due to sufficient integer width to represent the calculated size without overflow.


Impact

Information Disclosure (Primary): Heap memory from the ImageMagick process can be read during the out-of-bounds access. This memory may contain:

  • Previously processed image data
  • Environment variables
  • File paths
  • Cached credentials (in multi-tenant environments)

The leaked data can be embedded in the converted output image or extracted via side-channel analysis.

Denial of Service (Secondary): Reading unmapped memory regions triggers SIGSEGV, causing ImageMagick process termination and service disruption in automated image processing pipelines.


Proof of Concept

Technical details are provided for validation purposes. No executable exploit code is distributed.

Triggering Conditions

  • ImageMagick version < 7.1.2-10 compiled for 32-bit architecture
  • Maliciously crafted TIM file with header bytes specifying width=65535, height=65535
  • Processing via convert, magick, or any ImageMagick API call

Expected Behavior (Vulnerable)

root@kitploit:~
$ convert malicious.tim output.png
Segmentation fault (core dumped)

Or successful conversion with leaked heap data embedded in output.

Expected Behavior (Patched)

root@kitploit:~
$ convert malicious.tim output.png
convert: Memory allocation failed `malicious.tim' @ error/tim.c/ReadTIMImage/XXX.

Remediation

For Administrators

Update ImageMagick to version 7.1.2-10 or later:

root@kitploit:~
# Verify current version
convert --version

# Update using package manager
apt update && apt upgrade imagemagick      # Debian/Ubuntu
yum update imagemagick                     # RHEL/CentOS
brew upgrade imagemagick                   # macOS

For Developers

Implement overflow checking before arithmetic operations:

root@kitploit:~
// Insecure
image_size = 2 * width * height;

// Secure
if (height != 0 && width > (SIZE_MAX / 2) / height) {
    ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
}
image_size = 2 * width * height;

Apply input validation and sanity limits on dimension values before performing calculations.


References

  • CVE Record: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2025-66628
  • GitHub Advisory: https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-6hjr-v6g4-3fm8
  • ImageMagick Repository: https://github.com/ImageMagick/ImageMagick
  • CWE-190: https://cwe.mitre.org/data/definitions/190.html

Discovery Methodology

This vulnerability was identified using variant analysis. Following disclosure of a similar integer overflow in ImageMagick's BMP decoder, a systematic review of legacy format parsers was conducted. Pattern matching for unchecked width * height calculations led to identification of the same flaw in the TIM parser.

Legacy image format decoders (TIM, SGI, VIFF, etc.) represent high-value targets due to infrequent security audits and reliance on unsafe C arithmetic.


Responsible Disclosure

This vulnerability was reported privately to ImageMagick maintainers via GitHub Security Advisories. Public disclosure occurred only after patch availability and CVE assignment. This research was conducted ethically under responsible disclosure principles.

Discoverer

SUMIT SHAH

Researcher: SUMIT SHAH

  • LinkedIn: linkedin.com/in/sumit-shah-614625350
  • Instagram: @hacksagex
Download Tool