Miggo Logo

CVE-2025-57807: ImageMagick BlobStream Forward-Seek Under-Allocation

3.8

CVSS Score
3.1

Basic Information

EPSS Score
-
Published
9/5/2025
Updated
9/5/2025
KEV Status
No
Technology
TechnologyC#

Technical Details

CVSS Vector
CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:U/C:L/I:L/A:L
Package NameEcosystemVulnerable VersionsFirst Patched Version
Magick.NET-Q16-x64nuget< 14.8.214.8.2
Magick.NET-Q8-x64nuget< 14.8.214.8.2
Magick.NET-Q16-HDRI-x64nuget< 14.8.214.8.2
Magick.NET-Q8-OpenMP-x64nuget< 14.8.214.8.2
Magick.NET-Q16-HDRI-OpenMP-x64nuget< 14.8.214.8.2
Magick.NET-Q16-OpenMP-x64nuget< 14.8.214.8.2
Magick.NET-Q8-arm64nuget< 14.8.214.8.2
Magick.NET-Q16-arm64nuget< 14.8.214.8.2
Magick.NET-Q16-OpenMP-arm64nuget< 14.8.214.8.2
Magick.NET-Q8-OpenMP-arm64nuget< 14.8.214.8.2
Magick.NET-Q16-HDRI-OpenMP-arm64nuget< 14.8.214.8.2
Magick.NET-Q16-HDRI-arm64nuget< 14.8.214.8.2

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability is a heap-based buffer overflow in ImageMagick's MagickCore/blob.c. The root cause of the vulnerability lies in the WriteBlob function when used in conjunction with SeekBlob on a memory-backed BlobStream.

The exploit scenario unfolds in two steps:

  1. An attacker uses the SeekBlob function to move the internal offset of a blob to a position far beyond its currently allocated size. The SeekBlob function itself is not flawed; it correctly updates the offset as requested.
  2. The attacker then calls WriteBlob to write data to the blob. The vulnerable version of WriteBlob fails to correctly calculate the amount of memory required to accommodate the write at the new, large offset. Instead of calculating the required size based on offset + length, it calculates it based on extent + length + quantum. When the offset is significantly larger than the extent, this results in an undersized memory allocation.

The subsequent memmove operation within WriteBlob attempts to write the data at the specified offset, which now points to a location outside the bounds of the newly allocated (but too small) buffer. This out-of-bounds write corrupts the heap, which can lead to a crash (denial of service) or, potentially, arbitrary code execution.

The provided patch addresses this by changing the allocation logic in both WriteBlob and the inline function WriteBlobStream. The corrected code first calculates the required size (extent) based on the offset and length of the data to be written, ensuring that the buffer is always allocated to a sufficient size to prevent the overflow.

Vulnerable functions

WriteBlob
MagickCore/blob.c
The function `WriteBlob` is vulnerable to a heap-based buffer overflow. When handling a `BlobStream`, if `SeekBlob` was previously used to move the file offset far beyond the current end of the blob, `WriteBlob` would not allocate sufficient memory for the subsequent write. The memory allocation calculation, `blob_info->extent+=length+blob_info->quantum;`, did not account for the large offset, only the current extent and the length of the data to be written. This resulted in a smaller buffer being allocated than what was required. The subsequent `memmove` to `data + offset` would then write data out of the bounds of the allocated heap memory, leading to memory corruption and potential remote code execution.
WriteBlobStream
MagickCore/blob.c
The inline function `WriteBlobStream` had a similar vulnerability to `WriteBlob`. It also incorrectly calculated the required extent when writing to a blob, not taking into account a potential large offset. The patch corrected the calculation to be based on the actual required size, which includes the offset.

WAF Protection Rules

WAF Rule

**R*port*r:** Lumin* M*s*uw* **Pro*u*t:** Im***M**i*k * (M**i*k*or*) ***ompon*nt:** `M**i*k*or*/*lo*.*` (*lo* I/O - *lo*Str**m) **T*st**:** *.*.*-* (sour** t**) *n* *.*.*-* (*om**r*w), m**OS *rm**, *l*n*-**, Q**-**RI **Imp**t:** ***p out-o*-*

Reasoning

T** vuln*r**ility is * ***p-**s** *u***r ov*r*low in Im***M**i*k's `M**i*k*or*/*lo*.*`. T** root **us* o* t** vuln*r**ility li*s in t** `Writ**lo*` *un*tion w**n us** in *onjun*tion wit* `S**k*lo*` on * m*mory-***k** `*lo*Str**m`. T** *xploit s**n*r