Advisory
GHSA-cjc8-g9w8-chfw
Also known as: CVE-2025-55004
Summary
imagemagick: heap-buffer overflow read in MNG magnification with alpha
Details
Vulnerability Details
When performing image magnification in ReadOneMNGIMage (in coders/png.c), there is an issue around the handling of images with separate alpha channels.
When loading an image with a color type that implies a separate alpha channel (ie. jng_color_type >= 12), we will load the alpha pixels in this loop:
if (logging != MagickFalse)
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" Reading alpha from alpha_blob.");
jng_image=ReadImage(alpha_image_info,exception);
if (jng_image != (Image *) NULL)
for (y=0; y < (ssize_t) image->rows; y++)
{
s=GetVirtualPixels(jng_image,0,y,image->columns,1,exception);
q=GetAuthenticPixels(image,0,y,image->columns,1,exception); // [0]
if ((s == (const Quantum *) NULL) || (q == (Quantum *) NULL))
break;
if (image->alpha_trait != UndefinedPixelTrait)
for (x=(ssize_t) image->columns; x != 0; x--)
{
SetPixelAlpha(image,GetPixelRed(jng_image,s),q);
q+=(ptrdiff_t) GetPixelChannels(image);
s+=(ptrdiff_t) GetPixelChannels(jng_image);
}
else
for (x=(ssize_t) image->columns; x != 0; x--)
{
Quantum
alpha;
alpha=GetPixelRed(jng_image,s);
SetPixelAlpha(image,alpha,q);
if (alpha != OpaqueAlpha)
image->alpha_trait=BlendPixelTrait; // [1]
q+=(ptrdiff_t) GetPixelChannels(image);
s+=(ptrdiff_t) GetPixelChannels(jng_image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
Note that at \[1\] we update image->alpha_trait, but if our alpha image only contains non-opaque pixels in the last row, we do not call GetAuthenticPixels (at \[0\]) after this change has been made.
The next call to GetAuthenticPixels will then call down into ResetPixelChannelMap which adds the new alpha channel to the image channel mappings and metadata.
If we then pass this image into the MAGN chunk type, we can see that at \[2\] we calculate the sizes for intermediate buffers next and prev, before calling GetAuthenticPixels at \[4\].
After the call at \[4\], the image->num_channels has increased to include the new alpha channel, and now length and the previously allocated next and prev buffers are too small. Fortunately length is always used when copying into the buffers, but when reading pixels from the buffers, we call GetPixelXXX which assumes the layout of the current image, which requires a larger allocation.
The pixel copying loop will subsequently read beyond the end of the allocation at \[5\].
/* 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; // [2]
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); // [4]
(void) memcpy(next,n,length);
for (y=0; y < (ssize_t) image->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 <= 1 && y == (ssize_t) image->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 < (ssize_t) image->rows-1)
{
n=GetAuthenticPixels(image,0,y+1,image->columns,1,
exception);
(void) memcpy(next,n,length);
}
for (i=0; i < m; i++, yy++)
{
Quantum
*pixels;
assert(yy < (ssize_t) large_image->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);
for (x=(ssize_t) image->columns-1; x >= 0; x--)
{
/* To do: get color as function of indexes[x] */
/*
if (image->storage_class == PseudoClass)
{
}
*/
if (magn_methy <= 1)
{
/* replicate previous */
SetPixelRed(large_image,GetPixelRed(image,pixels),q); // [5]
SetPixelGreen(large_image,GetPixelGreen(image,
pixels),q);
SetPixelBlue(large_image,GetPixelBlue(image,
pixels),q);
SetPixelAlpha(large_image,GetPixelAlpha(image,
pixels),q);
}
This can likely be used to leak subsequent memory contents into the output image.
The attached proof-of-concept triggers this issue and is not blocked by any of the default security policies.
Affected Version(s)
The issue has been successfully reproduced:
- at commit
3e37a7f15fcb1aa80e6beae3898e684309c2ecbe
- in stable release
7.1.2-0
Build Instructions
git clone https://github.com/imagemagick/imagemagick
cd imagemagick
export CC=clang
export CXX=clang++
export CFLAGS="-fsanitize=address -O0 -ggdb"
export CXXFLAGS="-fsanitize=address -O0 -ggdb"
export LDFLAGS="-fsanitize=address -O0 -ggdb"
./configure --disable-shared --disable-docs --with-jxl
make -jSeverity
High Basis: The source's own band: HIGH
Dates
- Published
- 2025-08-25 15:58 UTC
- Modified
- 2026-09-10 03:50 UTC
Affected packages and fixes
| Package | Fix |
|---|---|
| Magick.NET-Q16-AnyCPU | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-HDRI-AnyCPU | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-HDRI-OpenMP-arm64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-HDRI-OpenMP-x64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-HDRI-arm64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-HDRI-x64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-HDRI-x86 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-OpenMP-arm64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-OpenMP-x64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-arm64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-x64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q16-x86 | The export has no generic command for this ecosystem. |
| Magick.NET-Q8-AnyCPU | The export has no generic command for this ecosystem. |
| Magick.NET-Q8-OpenMP-arm64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q8-OpenMP-x64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q8-arm64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q8-x64 | The export has no generic command for this ecosystem. |
| Magick.NET-Q8-x86 | The export has no generic command for this ecosystem. |
Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Links
Source
Source: GitHub Advisory Database (reviewed advisories) · CC BY 4.0