GitHub Advisoryadvisory · NuGet
GHSA-qp29-wxp5-wh82 imagemagick: integer overflows in MNG magnification
HIGH
Official page ↗
- Aliases
- CVE-2025-55154
- Ecosystem
- NuGet
- Packages
- Magick.NET-Q8-x86, Magick.NET-Q8-x64, Magick.NET-Q8-arm64, Magick.NET-Q8-OpenMP-x64, Magick.NET-Q8-OpenMP-arm64, Magick.NET-Q8-AnyCPU, Magick.NET-Q16-x86, Magick.NET-Q16-x64, Magick.NET-Q16-arm64, Magick.NET-Q16-OpenMP-x64, Magick.NET-Q16-OpenMP-arm64, Magick.NET-Q16-HDRI-x86, Magick.NET-Q16-HDRI-x64, Magick.NET-Q16-HDRI-arm64, Magick.NET-Q16-HDRI-OpenMP-x64, Magick.NET-Q16-HDRI-OpenMP-arm64, Magick.NET-Q16-HDRI-AnyCPU, Magick.NET-Q16-AnyCPU
- Severity
- High
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
- Weaknesses
- CWE-190
- Reviewed
- 2025-08-25
Affected packages
• NuGet Magick.NET-Q8-x86: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q8-x64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q8-arm64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q8-OpenMP-x64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q8-OpenMP-arm64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q8-AnyCPU: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-x86: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-x64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-arm64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-OpenMP-x64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-OpenMP-arm64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-HDRI-x86: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-HDRI-x64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-HDRI-arm64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-HDRI-OpenMP-x64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-HDRI-OpenMP-arm64: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-HDRI-AnyCPU: < 14.8.0 → fixed in 14.8.0
• NuGet Magick.NET-Q16-AnyCPU: < 14.8.0 → fixed in 14.8.0
Description
Vulnerability Details
The magnified size calculations in `ReadOneMNGIMage` (in `coders/png.c`) are unsafe and can overflow, leading to memory corruption.
The source snippet below is heavily abbreviated due to the size of the function, but hopefully the important points are captured.
```c
static Image *ReadOneMNGImage(MngReadInfo* mng_info,
const ImageInfo *image_info,ExceptionInfo *exception)
{
// Lots of stuff, this is effectively a state machine for the MNG rendering commands,
// skip to the point where we start processing the "MAGN" command.
if (memcmp(type,mng_MAGN,4) == 0)
{
png_uint_16
magn_first,
magn_last,
magn_mb,
magn_ml,
magn_mr,
magn_mt,
magn_mx,
magn_my,
magn_methx,
magn_methy;
// Details unimportant, but each of the `magn_xxx` variables is read from the file.
if (magn_first == 0 || magn_last == 0)
{
/* Save the magnification factors for object 0 */
mng_info->magn_mb=magn_mb;
mng_info->magn_ml=magn_ml;
mng_info->magn_mr=magn_mr;
mng_info->magn_mt=magn_mt;
mng_info->magn_mx=magn_mx;
mng_info->magn_my=magn_my;
mng_info->magn_methx=magn_methx;
mng_info->magn_methy=magn_methy;
}
}
// Details unimportant, we load the image to be scaled and store it in `image`
if (mng_type)
{
MngBox
crop_box;
if (((mng_info->magn_methx > 0) && (mng_info->magn_methx magn_methy > 0) && (mng_info->magn_methy columns == 1)
mng_info->magn_methx = 1;
if (image->rows == 1)
mng_info->magn_methy = 1;
if (mng_info->magn_methx == 1)
{
magnified_width=mng_info->magn_ml; // [0]
if (image->columns > 1)
magnified_width += mng_info->magn_mr; // [1]
if (image->columns > 2)
magnified_width += (png_uint_32)
((image->columns-2)*(mng_info->magn_mx)); // [2]
}
// Different cases handle available scaling kinds, all of which have similar issues...
// We now check whether the output image is larger than the input image in either
// dimension, and if so, we will allocate a new image buffer of size
// `magnified_width * magnified_height`.
if (magnified_height > image->rows ||
magnified_width > image->columns)
{
Image
*large_image;
// Snip...
large_image->columns=magnified_width;
large_image->rows=magnified_height;
magn_methx=mng_info->magn_methx;
magn_methy=mng_info->magn_methy;
// In between here, we allocate the pixel buffer for `large_image`.
/* magnify the rows into the right side of the large image */
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Magnify the rows to %.20g",
(double) large_image->rows);
m=(ssize_t) mng_info->magn_mt;
yy=0;
length=(size_t) GetPixelChannels(image)*image->columns;
next=(Quantum *) AcquireQuantumMemory(length,sizeof(*next));
prev=(Quantum *) AcquireQuantumMemory(length,sizeof(*prev));
if ((prev == (Quantum *) NULL) ||
(next == (Quantum *) NULL))
{
if (prev != (Quantum *) NULL)
prev=(Quantum *) RelinquishMagickMemory(prev);
if (next != (Quantum *) NULL)
next=(Quantum *) RelinquishMagickMemory(next);
image=DestroyImageList(image);
ThrowReaderException(ResourceLimitError,
"MemoryAllocationFailed");
}
n=GetAuthenticPixels(image,0,0,image->columns,1,exception);
(void) memcpy(next,n,length);
for (y=0; y rows; y++)
{
if (y == 0)
m=(ssize_t) mng_info->magn_mt;
else if (magn_methy > 1 && y == (ssize_t) image->rows-2)
m=(ssize_t) mng_info->magn_mb;
else if (magn_methy rows-1)
m=(ssize_t) mng_info->magn_mb;
else if (magn_methy > 1 && y == (ssize_t) image->rows-1)
m=1;
else
m=(ssize_t) mng_info->magn_my;
n=prev;
prev=next;
next=n;
if (y rows-1)
{
n=GetAuthenticPixels(image,0,y+1,image->columns,1,
exception);
(void) memcpy(next,n,length);
}
for (i=0; i rows);
pixels=prev;
n=next;
q=GetAuthenticPixels(large_image,0,yy,large_image->columns,
1,exception);
if (q == (Quantum *) NULL)
break;
q+=(ptrdiff_t) (large_image->columns-image->columns)*
GetPixelChannels(large_image); // [3]
```
If we look at the calculation for `magnified_width`, we can see that we are storing the results in a `png_uint32`. The operations at \[0\] and \[1\] are safe, since `mng_info->magn_ml` and `mng_info->magn_mx` are both 16-bit unsigned integers, but both the multiplication at \[2\] and the addition of the result of that multiplication to `magnified_width` can overflow, leading to a value of `magnified_width` that is smaller than required.
When we then operate on the pixel buffers, we use the original parameters for the magnification, and we assume (reasonably?) that the output buffer is larger than the input buffer when calculating where to write the upsampled/magnified pixel values. Unfortunately, after the overflow has happened, this assumption is no longer true, and the calculation at \[3\] will end up with a `q` pointer outside the buffer bounds.
This issue leads to an out-of-bounds write of controlled data beyond the bounds of a heap allocation.
Triggering this issue requires an `image` with large `columns` or `rows` (\~65535) which should be prevented by all of the example security policies (which set `width`/`height` limits of `8KP`).
Affected Version(s)
Verified on current HEAD (305e383c8ac7b30bc2ee96ab8c43ec96217ec2a9) and latest stable release (7.1.2-0).
Build Instructions
```shell
git clone https://github.com/imagemagick/imagemagick
cd imagemagick
export CC=clang
export CXX=clang++
export CFLAGS="-fsanitize=address"
export CXXFLAGS="-fsanitize=address"
export LDFLAGS="-fsanitize=address"
./configure --disable-shared --disable-docs --with-jxl
make -j
```
Reproduction
Test Case
This testcase is a python script that will generate an MNG file with a MAGN chunk that triggers this overflow leading to an out-of-bounds heap write.
```
import struct
import zlib
def create_chunk(chunk_type, data):
crc = zlib.crc32(chunk_type + data…
Related
Alias · CVE (1)
- CVE-2025-55154 ImageMagick is free and open-source software used for editing and manipulating digital images. vulnerability
Weakness · CWE (1)
- CWE-190 Integer Overflow or Wraparound weakness
References
- https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-qp29-wxp5-wh82 web
- https://nvd.nist.gov/vuln/detail/CVE-2025-55154 advisory
- https://github.com/ImageMagick/ImageMagick package
- https://github.com/dlemstra/Magick.NET/releases/tag/14.8.0 web
- https://issuetracker.google.com/savedsearches/7155917 web
- https://lists.debian.org/debian-lts-announce/2025/09/msg00012.html web