Описание
ImageMagick has a Stack Buffer Overflow in image.c
Summary
In ImageMagick's magick mogrify
command, specifying multiple consecutive %d
format specifiers in a filename template causes internal pointer arithmetic to generate an address below the beginning of the stack buffer, resulting in a stack overflow through vsnprintf()
.
Details
- Vulnerability Type: CWE-124: Buffer Underwrite
- Affected Component: MagickCore/image.c - Format processing within InterpretImageFilename()
- Affected Version: ImageMagick 7.1.1-47 (as of commit 82572afc, June 2025)
- CWE-124: Buffer Underwrite: A vulnerability where writing occurs to memory addresses before the beginning of a buffer. This is caused by a design flaw in fixed offset correction, resulting in negative pointer arithmetic during consecutive format specifier processing.
Reproduction
Tested Environment
- Operating System: Ubuntu 22.04 LTS
- Architecture: x86_64
- Compiler: gcc with AddressSanitizer (gcc version: 11.4.0)
Reproduction Steps
Output
Affected Code
In MagickCore/image.c
, within the InterpretImageFilename()
function:
Technical Analysis
This vulnerability is caused by an inconsistency in the template expansion processing within InterpretImageFilename()
.
The format specifiers %d
, %o
, and %x
in templates are replaced with integer values by FormatLocaleString()
, but the output buffer position is calculated by filename + (p - format - offset)
.
The offset
variable is cumulatively incremented to correct the output length of %d
etc., but the design using a static offset += (4 - field_width)
causes offset
to increase excessively when %
specifiers are consecutive in the template, creating a dangerous state where the write destination address points before filename
.
The constant 4
was likely chosen based on the character count of typical format specifiers like %03d
(total of 4 characters: %
, 0
, 3
, d
). However, in reality, there are formats with only 2 characters like %d
, and formats with longer width specifications (e.g., %010d
), so this uniform constant-based correction is inconsistent with actual template structures.
As a result, when the correction value becomes excessive, offset
exceeds the relative position p - format
within the template, generating a negative index. This static and template-independent design of the correction processing is the root cause of this vulnerability.
This causes vsnprintf()
to write outside the stack buffer range, which is detected by AddressSanitizer as a stack-buffer-overflow
.
Ссылки
- https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-qh3h-j545-h8c9
- https://nvd.nist.gov/vuln/detail/CVE-2025-53101
- https://github.com/ImageMagick/ImageMagick/commit/66dc8f51c11b0ae1f1cdeacd381c3e9a4de69774
- https://github.com/ImageMagick/ImageMagick6/commit/643deeb60803488373cd4799b24d5786af90972e
- https://github.com/dlemstra/Magick.NET/releases/tag/14.7.0
Пакеты
Magick.NET-Q16-AnyCPU
< 14.7.0
14.7.0
Magick.NET-Q16-HDRI-AnyCPU
< 14.7.0
14.7.0
Magick.NET-Q16-HDRI-OpenMP-arm64
< 14.7.0
14.7.0
Magick.NET-Q16-HDRI-OpenMP-x64
< 14.7.0
14.7.0
Magick.NET-Q16-HDRI-arm64
< 14.7.0
14.7.0
Magick.NET-Q16-HDRI-x64
< 14.7.0
14.7.0
Magick.NET-Q16-HDRI-x86
< 14.7.0
14.7.0
Magick.NET-Q16-OpenMP-arm64
< 14.7.0
14.7.0
Magick.NET-Q16-OpenMP-x64
< 14.7.0
14.7.0
Magick.NET-Q16-arm64
< 14.7.0
14.7.0
Magick.NET-Q16-x64
< 14.7.0
14.7.0
Magick.NET-Q16-x86
< 14.7.0
14.7.0
Magick.NET-Q8-AnyCPU
< 14.7.0
14.7.0
Magick.NET-Q8-OpenMP-arm64
< 14.7.0
14.7.0
Magick.NET-Q8-OpenMP-x64
< 14.7.0
14.7.0
Magick.NET-Q8-arm64
< 14.7.0
14.7.0
Magick.NET-Q8-x64
< 14.7.0
14.7.0
Magick.NET-Q8-x86
< 14.7.0
14.7.0
Связанные уязвимости
ImageMagick is free and open-source software used for editing and manipulating digital images. In versions prior to 7.1.2-0 and 6.9.13-26, in ImageMagick's `magick mogrify` command, specifying multiple consecutive `%d` format specifiers in a filename template causes internal pointer arithmetic to generate an address below the beginning of the stack buffer, resulting in a stack overflow through `vsnprintf()`. Versions 7.1.2-0 and 6.9.13-26 fix the issue.
ImageMagick is free and open-source software used for editing and manipulating digital images. In versions prior to 7.1.2-0 and 6.9.13-26, in ImageMagick's `magick mogrify` command, specifying multiple consecutive `%d` format specifiers in a filename template causes internal pointer arithmetic to generate an address below the beginning of the stack buffer, resulting in a stack overflow through `vsnprintf()`. Versions 7.1.2-0 and 6.9.13-26 fix the issue.
ImageMagick is free and open-source software used for editing and manipulating digital images. In versions prior to 7.1.2-0 and 6.9.13-26, in ImageMagick's `magick mogrify` command, specifying multiple consecutive `%d` format specifiers in a filename template causes internal pointer arithmetic to generate an address below the beginning of the stack buffer, resulting in a stack overflow through `vsnprintf()`. Versions 7.1.2-0 and 6.9.13-26 fix the issue.
ImageMagick is free and open-source software used for editing and mani ...