A single root cause in the CLAHE implementation — tile width/height becoming zero — produces two distinct but related unsafe behaviors.
Vulnerabilities exists in the CLAHEImage() function of ImageMagick’s MagickCore/enhance.c.
tile_info.height == 0, the expression tile_info.height - 1 (unsigned) wraps to a very large value; using that value in pointer arithmetic yields a huge offset and OOB memory access (leading to memory corruption, SIGSEGV, or resource exhaustion).... / tile_info.width or ... % tile_info.height without re-checking for zero, causing immediate division-by-zero crashes under sanitizers or abort at runtime.Both behaviors are triggered by the same invalid tile condition (e.g., CLI exact -clahe 0x0! or automatic tile derivation dim >> 3 == 0 for very small images).
Location: MagickCore/enhance.c, around line 609
Version tested: 7.1.2-8 (local ASan(undefined). /UBSan build)
Vulnerable code
enhance.c: 609
p += (ptrdiff_t) clahe_info->width * (tile.height - 1);
Root Cause
tile.height == 0, then (tile.height - 1) underflows to UINT_MAX.clahe_info->width yields a huge value close to SIZE_MAX.p causes pointer arithmetic underflow.File / Location: MagickCore/enhance.c, around line 669
Version tested: 7.1.2-8 (local ASan(undefined). /UBSan build)
vulnerable code
enhance.c: 669-673
if ((image->columns % tile_info.width) != 0)
tile_info.x=(ssize_t) (tile_info.width-(image->columns % tile_info.width));
tile_info.y=0;
if ((image->rows % tile_info.height) != 0)
tile_info.y=(ssize_t) (tile_info.height-(image->rows % tile_info.height));
Root cause
Missing input validation / bounds checks after computing default tile dimensions:
If either tile_info.width or tile_info.height is 0, this triggers a division by zero. Zeros can reach this point through:
clahe 0x0! (the ! forces zero to be used verbatim).0 (no !), the code derives a default from the image size (e.g., dim >> 3). For images with dim < 8, this result is 0 unless clamped.Environment
Built with AddressSanitizer and UndefinedBehaviorSanitizer enabled.
export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
export ASAN_OPTIONS=abort_on_error=1:allocator_may_return_null=1:detect_leaks=0
Command
./magick xc:black -clahe 0x0 null:
Output
MagickCore/enhance.c:609:6: runtime error: addition of unsigned offset overflowed
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior MagickCore/enhance.c:609:6 in CLAHEImage
./magick -size 10x10 xc:black -clahe 0x0 null:
Command
./magick -size 16x2 gradient: -type TrueColor -depth 8 -clahe 0x0! null:
Output
Apply in CLAHEImage() after tile_info is computed but before any division/modulus/pointer arithmetic:
if (exact_tiles_requested && (tile_info.width == 0 || tile_info.height == 0)) {
ThrowMagickException(exception, GetMagickModule(), OptionError,
"CLAHEInvalidTile", "%lux%lu",
(unsigned long) tile_info.width,
(unsigned long) tile_info.height);
return (Image *) NULL;
}
if (!exact_tiles_requested) {
tile_info.width = (tile_info.width == 0) ? MagickMax((size_t)1, image->columns >> 3) : tile_info.width;
tile_info.height = (tile_info.height == 0) ? MagickMax((size_t)1, image->rows >> 3) : tile_info.height;
}
if (tile_info.width == 0 || tile_info.height == 0) {
ThrowMagickException(exception, GetMagickModule(), OptionError,
"CLAHEInvalidTile", "%lux%lu",
(unsigned long) tile_info.width,
(unsigned long) tile_info.height);
return (Image *) NULL;
}
ssize_t tile_h_minus1 = (ssize_t)tile_info.height - 1;
if (tile_h_minus1 < 0) {
ThrowMagickException(exception, GetMagickModule(), OptionError,
"CLAHEInvalidTile", "%lux%lu",
(unsigned long) tile_info.width,
(unsigned long) tile_info.height);
return (Image *) NULL;
}
p += (ptrdiff_t) clahe_info->width * tile_h_minus1;
Notes about exact_tiles_requested: if the CLI/Wand parser already exposes whether ! was present, use it. If not, add a parse-time flag so CLAHEImage can know whether 0 is literal or auto.
Bug Hunting Master Program, HSpace/Findthegap
Youngmin Kim kunshim@naver.com
Woojin Park
Youngin Won
@amethyst0225 youngin04@korea.ac.kr
Siyeon Han
Shinyoung Won
{
"license": "CC-BY-4.0",
"sources": [
{
"database_specific": {
"status": "Analyzed"
},
"html_url": "https://nvd.nist.gov/vuln/detail/CVE-2025-62594",
"id": "CVE-2025-62594",
"imported": "2026-07-30T14:08:44.444Z",
"modified": "2026-06-17T09:52:07.790Z",
"published": "2025-10-27T20:15:54.893Z",
"url": "https://services.nvd.nist.gov/rest/json/cves/2.0?cveId=CVE-2025-62594"
},
{
"html_url": "https://github.com/advisories/GHSA-wpp4-vqfq-v4hp",
"id": "GHSA-wpp4-vqfq-v4hp",
"imported": "2026-07-30T14:10:17.307Z",
"modified": "2025-10-31T09:29:26Z",
"published": "2025-10-27T23:33:10Z",
"url": "https://api.github.com/advisories/GHSA-wpp4-vqfq-v4hp"
},
{
"html_url": "https://euvd.enisa.europa.eu/vulnerability/EUVD-2025-36365",
"id": "EUVD-2025-36365",
"imported": "2026-07-30T14:08:55.968Z",
"modified": "2025-10-27T20:23:20Z",
"published": "2025-10-27T20:00:33Z",
"url": "https://euvdservices.enisa.europa.eu/api/enisaid?id=EUVD-2025-36365"
}
]
}