CVE-2025-53101: ImageMagick has Stack Buffer Overflow in image.c

Published Jul 14, 2025
·
Updated

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: x8664 - Compiler: gcc with AddressSanitizer (gcc version: 11.4.0)

Reproduction Steps

bash Clone source git clone --depth 1 --branch 7.1.1-47 https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.1.1 cd ImageMagick-7.1.1

Build with ASan CFLAGS="-g -O0 -fsanitize=address -fno-omit-frame-pointer" CXXFLAGS="$CFLAGS" LDFLAGS="-fsanitize=address" ./configure --enable-maintainer-mode --enable-shared && make -j$(nproc) && make install

Trigger crash ./utilities/magick mogrify %d%d

Output

plaintext ==4155==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffda834caae at pc 0x7f1ea367fb27 bp 0x7ffda834b680 sp 0x7ffda834ae10 WRITE of size 2 at 0x7ffda834caae thread T0 #0 0x7f1ea367fb26 in interceptorvsnprintf ../../../../src/libsanitizer/sanitizercommon/sanitizercommoninterceptors.inc:1668 #1 0x7f1ea2dc9e3e in FormatLocaleStringList MagickCore/locale.c:470 #2 0x7f1ea2dc9fd9 in FormatLocaleString MagickCore/locale.c:495 #3 0x7f1ea2da0ad5 in InterpretImageFilename MagickCore/image.c:1696 #4 0x7f1ea2c6126b in ReadImages MagickCore/constitute.c:1051 #5 0x7f1ea27ef29b in MogrifyImageCommand MagickWand/mogrify.c:3858 #6 0x7f1ea278e95d in MagickCommandGenesis MagickWand/magick-cli.c:177 #7 0x560813499a0c in MagickMain utilities/magick.c:153 #8 0x560813499cba in main utilities/magick.c:184 #9 0x7f1ea1c0bd8f in libcstartcallmain ../sysdeps/nptl/libcstartcallmain.h:58 #10 0x7f1ea1c0be3f in libcstartmainimpl ../csu/libc-start.c:392 #11 0x560813499404 in start (/root/workdir/ImageMagick/utilities/.libs/magick+0x2404)

Address 0x7ffda834caae is located in stack of thread T0 at offset 62 in frame #0 0x7f1ea2c60f62 in ReadImages MagickCore/constitute.c:1027

This frame has 2 object(s): [32, 40) 'images' (line 1033) [64, 4160) 'readfilename' (line 1029) <== Memory access at offset 62 underflows this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork (longjmp and C++ exceptions are supported) SUMMARY: AddressSanitizer: stack-buffer-overflow ../../../../src/libsanitizer/sanitizercommon/sanitizercommoninterceptors.inc:1668 in interceptorvsnprintf Shadow bytes around the buggy address: 0x100035061900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100035061910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100035061920: 00 00 00 00 00 00 00 00 f3 f3 f3 f3 f3 f3 f3 f3 0x100035061930: f3 f3 f3 f3 f3 f3 f3 f3 00 00 00 00 00 00 00 00 0x100035061940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x100035061950: f1 f1 00 f2 f2[f2]00 00 00 00 00 00 00 00 00 00 0x100035061960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100035061970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100035061980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100035061990: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x1000350619a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb Shadow gap: cc ==4155==ABORTING

Affected Code

In MagickCore/image.c, within the InterpretImageFilename() function:

c MagickExport sizet InterpretImageFilename(const ImageInfo imageinfo, Image image,const char format,int value,char filename, ExceptionInfo exception) { ... for (p=strchr(format,'%'); p != (char ) NULL; p=strchr(p+1,'%')) { q=(char ) p+1; if (q == '%') { p=q+1; continue; } fieldwidth=0; if (q == '0') fieldwidth=(ssizet) strtol(q,&q,10); switch (q) { case 'd': case 'o': case 'x': { q++; c=(q); q='\0'; /--------Affected--------/ (void) FormatLocaleString(filename+(p-format-offset),(sizet) (MagickPathExtent-(p-format-offset)),p,value); offset+=(4-fieldwidth); /--------Affected--------/ q=c; (void) ConcatenateMagickString(filename,q,MagickPathExtent); canonical=MagickTrue; if ((q-1) != '%') break; p++; break; } case '[': { ... } default: break; } }

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 - fieldwidth) 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.

Other sources

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.

NVD

Affected Software

19 affected componentsFixes available
ImageMagick ImageMagick<7.1.2-0, <6.9.13-26
nuget/Magick.NET-Q8-x86<14.7.0
14.7.0
nuget/Magick.NET-Q8-arm64<14.7.0
14.7.0
nuget/Magick.NET-Q8-OpenMP-x64<14.7.0
14.7.0
nuget/Magick.NET-Q8-OpenMP-arm64<14.7.0
14.7.0
nuget/Magick.NET-Q8-AnyCPU<14.7.0
14.7.0
nuget/Magick.NET-Q16-x86<14.7.0
14.7.0
nuget/Magick.NET-Q16-arm64<14.7.0
14.7.0
nuget/Magick.NET-Q16-OpenMP-x64<14.7.0
14.7.0
nuget/Magick.NET-Q16-OpenMP-arm64<14.7.0
14.7.0
nuget/Magick.NET-Q16-HDRI-x86<14.7.0
14.7.0
nuget/Magick.NET-Q16-HDRI-x64<14.7.0
14.7.0
nuget/Magick.NET-Q16-HDRI-arm64<14.7.0
14.7.0
nuget/Magick.NET-Q16-HDRI-OpenMP-x64<14.7.0
14.7.0
nuget/Magick.NET-Q16-HDRI-OpenMP-arm64<14.7.0
14.7.0
nuget/Magick.NET-Q16-HDRI-AnyCPU<14.7.0
14.7.0
nuget/Magick.NET-Q16-AnyCPU<14.7.0
14.7.0
ImageMagick ImageMagick<6.9.13-26
ImageMagick ImageMagick>=7.0.0-0<7.1.2-0

Event History

Jul 14, 2025
CVE Published
via MITRE·07:51 PM
Data Sourced
via MITRE·07:51 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·08:15 PM
RemedyDescriptionSeverityWeaknessAffected Software
Aug 25, 2025
Advisory Published
via GitHub·03:43 PM
Data Sourced
via GitHub·03:43 PM
DescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2025-53101?

CVE-2025-53101 is categorized as a medium severity vulnerability, potentially leading to denial of service.

2

How do I fix CVE-2025-53101?

To fix CVE-2025-53101, update ImageMagick to version 7.1.2-0 or 6.9.13-26 or later.

3

What type of vulnerability is CVE-2025-53101?

CVE-2025-53101 is an internal pointer error that occurs in the `magick mogrify` command of ImageMagick.

4

Which versions of ImageMagick are affected by CVE-2025-53101?

ImageMagick versions prior to 7.1.2-0 and 6.9.13-26 are affected by CVE-2025-53101.

5

What is the potential impact of CVE-2025-53101?

The potential impact of CVE-2025-53101 includes causing crashes or denial of service in applications using ImageMagick.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203