Описание
ImageMagick has a Heap Buffer Overflow in InterpretImageFilename
Heap Buffer Overflow in InterpretImageFilename
Summary
A heap buffer overflow was identified in the InterpretImageFilename
function of ImageMagick. The issue stems from an off-by-one error that causes out-of-bounds memory access when processing format strings containing consecutive percent signs (%%
).
Environment
- OS: Arch Linux (Linux gmkhost 6.14.2-arch1-1 # 1 SMP PREEMPT_DYNAMIC Thu, 10 Apr 2025 18:43:59 +0000 x86_64 GNU/Linux (GNU libc) 2.41)
- Architecture: x86_64
- Compiler: gcc (GCC) 15.1.1 20250425
Reproduction
Build Instructions
Minimum Trigger
Crash Analysis
AddressSanitizer Output
Root Cause Analysis
The first command line argument is interpreted as MagickImageCommand
:
https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/utilities/magick.c#L83
It is invoked here: https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/magick-cli.c#L220
The execution then follows this path:
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/magick-cli.c#L1387
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/magick-cli.c#L586
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/magick-cli.c#L419
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/operation.c#L5391
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/operation.c#L5473
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickWand/operation.c#L4959
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickCore/constitute.c#L1009
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickCore/constitute.c#L1039
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickCore/image.c#L1649
- https://github.com/ImageMagick/ImageMagick/blob/8fff9b4f44d2e8b5cae2bd6db70930a144d15f12/MagickCore/image.c#L1674
The execution eventually reaches InterpretImageFilename
and enters a loop. The format
variable here is "%%"
. At this point, it is safe to access *(format + 2)
but not safe to access *(format + 3)
.
The first strchr
call returns a pointer equal to format
and assigns it to p
. Then q
is initialized with p + 1
(format + 1
), and *q
is '%'
, so the code enters the if branch. Here, p
is reassigned to q + 1
(format + 2
).
In the next iteration, p + 1
(format + 3
) is passed to strchr
, and when strchr
accesses it, this causes an out-of-bounds read.
Ссылки
- https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-hm4x-r5hc-794f
- https://nvd.nist.gov/vuln/detail/CVE-2025-53014
- https://github.com/ImageMagick/ImageMagick/commit/29d82726c7ec20c07c49ba263bdcea16c2618e03
- https://github.com/ImageMagick/ImageMagick6/commit/79b6ed03770781d996d1710b89fbb887e5ea758a
- 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. Versions prior to 7.1.2-0 and 6.9.13-26 have a heap buffer overflow in the `InterpretImageFilename` function. The issue stems from an off-by-one error that causes out-of-bounds memory access when processing format strings containing consecutive percent signs (`%%`). 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. Versions prior to 7.1.2-0 and 6.9.13-26 have a heap buffer overflow in the `InterpretImageFilename` function. The issue stems from an off-by-one error that causes out-of-bounds memory access when processing format strings containing consecutive percent signs (`%%`). 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. Versions prior to 7.1.2-0 and 6.9.13-26 have a heap buffer overflow in the `InterpretImageFilename` function. The issue stems from an off-by-one error that causes out-of-bounds memory access when processing format strings containing consecutive percent signs (`%%`). 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 ...