{"id":"JLSEC-2026-928","aliases":["JLSEC-2026-928"],"related":["CVE-2025-62594","EUVD-2025-36365","GHSA-wpp4-vqfq-v4hp"],"kind":"vulnerability","state":"published","title":"ImageMagick CLAHE : Unsigned underflow and division-by-zero lead to OOB pointer arithmetic and process crash (DoS)","summary":"## Summary\n\nA single root cause in the CLAHE implementation — tile width/height becoming zero — produces two distinct but related unsafe behaviors.\nVulnerabilities exists in the `CLAHEImage()` function of ImageMagick’s `MagickCore/enhance.c`.\n\n 1. Unsigned integer underflow → out-of-bounds pointer arithmetic (OOB): when `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).\n 2. **Division/modulus by zero**: where code performs `... / tile_info.width` or `... % tile_info.height` without re-checking for zero, causing immediate division-by-zero crashes under sanitizers or `abort` at runtime.\n\nBoth 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).\n\n* * *\n\n## Details\n\n### **Unsigned underflow(can lea to OOB)**\n\n  - Location: `MagickCore/enhance.c`, around line 609\n\n  - Version tested: 7.1.2-8 (local ASan(undefined). /UBSan build)\n  - Vulnerable code\n    \n    enhance.c: 609\n    \n    ```c\n    p += (ptrdiff_t) clahe_info->width * (tile.height - 1);\n    ```\n  - Root Cause\n    \n      + If `tile.height == 0`, then `(tile.height - 1)` underflows to `UINT_MAX`.\n      + Multiplication with `clahe_info->width` yields a huge value close to `SIZE_MAX`.\n      + Adding this to `p` causes pointer arithmetic underflow.\n\n### **Division-by-zero**\n\n  - File / Location: `MagickCore/enhance.c`, around line 669\n\n  - Version tested: 7.1.2-8 (local ASan(undefined). /UBSan build)\n  - vulnerable code\n    \n    enhance.c: 669-673\n    \n    ```c\n     if ((image->columns % tile_info.width) != 0)\n        tile_info.x=(ssize_t) (tile_info.width-(image->columns % tile_info.width));\n      tile_info.y=0;\n      if ((image->rows % tile_info.height) != 0)\n        tile_info.y=(ssize_t) (tile_info.height-(image->rows % tile_info.height));\n    ```\n  - Root cause\n    \n    Missing input validation / bounds checks after computing default tile dimensions:\n    \n    If either `tile_info.width` or `tile_info.height` is 0, this triggers a division by zero. Zeros can reach this point through:\n    \n     1. Exact tiles: CLI `clahe 0x0!` (the `!` forces zero to be used verbatim).\n     2. Auto tiles on tiny images: When a requested tile is `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.\n\n* * *\n\n## Reproduction\n\n### **Unsigned underflow**\n\n**Environment**\n\nBuilt with AddressSanitizer and UndefinedBehaviorSanitizer enabled.\n\n```c\nexport UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1\nexport ASAN_OPTIONS=abort_on_error=1:allocator_may_return_null=1:detect_leaks=0\n```\n\n**Command**\n\n```bash\n./magick xc:black -clahe 0x0 null:\n```\n\n**Output**\n\n```\nMagickCore/enhance.c:609:6: runtime error: addition of unsigned offset overflowed\nSUMMARY: UndefinedBehaviorSanitizer: undefined-behavior MagickCore/enhance.c:609:6 in CLAHEImage\n```\n\n`./magick -size 10x10 xc:black -clahe 0x0 null:`\n\n<img width=\"1068\" height=\"64\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cd9637ee-1d03-4066-834d-fda22410dd8b\" />\nmemory region corruption.\n`./magick -size 2000x2000 xc:black -clahe 0x0 null:`\n<img width=\"1069\" height=\"70\" alt=\"image\" src=\"https://github.com/user-attachments/assets/ecbab79c-a3c2-4e8c-96c9-8e2aa8f0d2b2\" />\n→ Significant memory consumption and evidence of memory region corruption.\n`./magick -size 4000x4000 xc:black -clahe 0x0 null:`\n<img width=\"776\" height=\"49\" alt=\"image\" src=\"https://github.com/user-attachments/assets/63a7cec5-616b-4aa5-87f3-a546a87e6625\" />\n→ Much larger memory usage; process appears to be aggressively consuming cache and address space.\n`./magick -size 8000x8000 xc:black -clahe 0x0 null:`\n<img width=\"748\" height=\"46\" alt=\"image\" src=\"https://github.com/user-attachments/assets/48b3aac8-98b3-4fbb-a5ca-4e7936bca44b\" />\n→ Memory usage escalates further and begins exhausting available cache. If left running, the process is likely to crash (DoS) after sustained allocation attempts.\n### **Division-by-zero**\n**Environment:** ASan/UBSan-enabled build.\n```c\nexport UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1\nexport ASAN_OPTIONS=abort_on_error=1:allocator_may_return_null=1:detect_leaks=0\n```\n\n**Command**\n\n```bash\n./magick -size 16x2 gradient: -type TrueColor -depth 8 -clahe 0x0! null:\n```\n\n**Output**\n\n<img width=\"1915\" height=\"818\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cfe44432-b429-49e4-8673-2ed55ba9a961\" />\n**Notes:** Without sanitizers, the process may terminate with just `Aborted` (still DoS).\n* * *\n## Impact\n  - Primary: Denial-of-Service — crash or sustained resource exhaustion (memory/cache thrash) when processing crafted parameters or small images via CLI or API. Attackers can trivially trigger via `clahe 0x0!` or by uploading very small images to services using ImageMagick.\n  - Secondary (theoretical): OOB memory accesses and memory corruption could potentially be combined with other vulnerabilities to achieve more severe outcomes; however, no reliable code execution was demonstrated from these PoCs alone.\n\n* * *\n\n## Suggested concrete patch snippets\n\nApply in `CLAHEImage()` after `tile_info` is computed but **before** any division/modulus/pointer arithmetic:\n\n```c\nif (exact_tiles_requested && (tile_info.width == 0 || tile_info.height == 0)) {\n  ThrowMagickException(exception, GetMagickModule(), OptionError,\n                       \"CLAHEInvalidTile\", \"%lux%lu\",\n                       (unsigned long) tile_info.width,\n                       (unsigned long) tile_info.height);\n  return (Image *) NULL;\n}\n\nif (!exact_tiles_requested) {\n  tile_info.width  = (tile_info.width  == 0) ? MagickMax((size_t)1, image->columns >> 3) : tile_info.width;\n  tile_info.height = (tile_info.height == 0) ? MagickMax((size_t)1, image->rows    >> 3) : tile_info.height;\n}\n\nif (tile_info.width == 0 || tile_info.height == 0) {\n  ThrowMagickException(exception, GetMagickModule(), OptionError,\n                       \"CLAHEInvalidTile\", \"%lux%lu\",\n                       (unsigned long) tile_info.width,\n                       (unsigned long) tile_info.height);\n  return (Image *) NULL;\n}\n\nssize_t tile_h_minus1 = (ssize_t)tile_info.height - 1;\nif (tile_h_minus1 < 0) {\n  ThrowMagickException(exception, GetMagickModule(), OptionError,\n                       \"CLAHEInvalidTile\", \"%lux%lu\",\n                       (unsigned long) tile_info.width,\n                       (unsigned long) tile_info.height);\n  return (Image *) NULL;\n}\np += (ptrdiff_t) clahe_info->width * tile_h_minus1;\n```\n\nNotes 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.\n\n* * *\n\n## Credit\n\n### Team Whys\n\n**Bug Hunting Master Program, HSpace/Findthegap**\n\n**Youngmin Kim**\nkunshim@naver.com\n\n**Woojin Park**\n\n[@jin-156](https://github.com/jin-156)\n[1203kids@gmail.com](mailto:1203kids@gmail.com)\n\n**Youngin Won**\n\n[@amethyst0225](https://github.com/amethyst0225)\n[youngin04@korea.ac.kr](mailto:youngin04@korea.ac.kr)\n\n**Siyeon Han**\n\n[@hanbunny](https://github.com/hanbunny)\n[kokosyeon@gmail.com](mailto:kokosyeon@gmail.com)\n\n**Shinyoung Won**\n\n[@yosiimich](yosimich123@gmail.com)\n[yosimich123@gmail.com](mailto:yosimich123@gmail.com)","summaryFormat":"markdown","summarySource":"jlsec","descriptions":[{"lang":"en","text":"## Summary\n\nA single root cause in the CLAHE implementation — tile width/height becoming zero — produces two distinct but related unsafe behaviors.\nVulnerabilities exists in the `CLAHEImage()` function of ImageMagick’s `MagickCore/enhance.c`.\n\n 1. Unsigned integer underflow → out-of-bounds pointer arithmetic (OOB): when `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).\n 2. **Division/modulus by zero**: where code performs `... / tile_info.width` or `... % tile_info.height` without re-checking for zero, causing immediate division-by-zero crashes under sanitizers or `abort` at runtime.\n\nBoth 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).\n\n* * *\n\n## Details\n\n### **Unsigned underflow(can lea to OOB)**\n\n  - Location: `MagickCore/enhance.c`, around line 609\n\n  - Version tested: 7.1.2-8 (local ASan(undefined). /UBSan build)\n  - Vulnerable code\n    \n    enhance.c: 609\n    \n    ```c\n    p += (ptrdiff_t) clahe_info->width * (tile.height - 1);\n    ```\n  - Root Cause\n    \n      + If `tile.height == 0`, then `(tile.height - 1)` underflows to `UINT_MAX`.\n      + Multiplication with `clahe_info->width` yields a huge value close to `SIZE_MAX`.\n      + Adding this to `p` causes pointer arithmetic underflow.\n\n### **Division-by-zero**\n\n  - File / Location: `MagickCore/enhance.c`, around line 669\n\n  - Version tested: 7.1.2-8 (local ASan(undefined). /UBSan build)\n  - vulnerable code\n    \n    enhance.c: 669-673\n    \n    ```c\n     if ((image->columns % tile_info.width) != 0)\n        tile_info.x=(ssize_t) (tile_info.width-(image->columns % tile_info.width));\n      tile_info.y=0;\n      if ((image->rows % tile_info.height) != 0)\n        tile_info.y=(ssize_t) (tile_info.height-(image->rows % tile_info.height));\n    ```\n  - Root cause\n    \n    Missing input validation / bounds checks after computing default tile dimensions:\n    \n    If either `tile_info.width` or `tile_info.height` is 0, this triggers a division by zero. Zeros can reach this point through:\n    \n     1. Exact tiles: CLI `clahe 0x0!` (the `!` forces zero to be used verbatim).\n     2. Auto tiles on tiny images: When a requested tile is `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.\n\n* * *\n\n## Reproduction\n\n### **Unsigned underflow**\n\n**Environment**\n\nBuilt with AddressSanitizer and UndefinedBehaviorSanitizer enabled.\n\n```c\nexport UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1\nexport ASAN_OPTIONS=abort_on_error=1:allocator_may_return_null=1:detect_leaks=0\n```\n\n**Command**\n\n```bash\n./magick xc:black -clahe 0x0 null:\n```\n\n**Output**\n\n```\nMagickCore/enhance.c:609:6: runtime error: addition of unsigned offset overflowed\nSUMMARY: UndefinedBehaviorSanitizer: undefined-behavior MagickCore/enhance.c:609:6 in CLAHEImage\n```\n\n`./magick -size 10x10 xc:black -clahe 0x0 null:`\n\n<img width=\"1068\" height=\"64\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cd9637ee-1d03-4066-834d-fda22410dd8b\" />\nmemory region corruption.\n`./magick -size 2000x2000 xc:black -clahe 0x0 null:`\n<img width=\"1069\" height=\"70\" alt=\"image\" src=\"https://github.com/user-attachments/assets/ecbab79c-a3c2-4e8c-96c9-8e2aa8f0d2b2\" />\n→ Significant memory consumption and evidence of memory region corruption.\n`./magick -size 4000x4000 xc:black -clahe 0x0 null:`\n<img width=\"776\" height=\"49\" alt=\"image\" src=\"https://github.com/user-attachments/assets/63a7cec5-616b-4aa5-87f3-a546a87e6625\" />\n→ Much larger memory usage; process appears to be aggressively consuming cache and address space.\n`./magick -size 8000x8000 xc:black -clahe 0x0 null:`\n<img width=\"748\" height=\"46\" alt=\"image\" src=\"https://github.com/user-attachments/assets/48b3aac8-98b3-4fbb-a5ca-4e7936bca44b\" />\n→ Memory usage escalates further and begins exhausting available cache. If left running, the process is likely to crash (DoS) after sustained allocation attempts.\n### **Division-by-zero**\n**Environment:** ASan/UBSan-enabled build.\n```c\nexport UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1\nexport ASAN_OPTIONS=abort_on_error=1:allocator_may_return_null=1:detect_leaks=0\n```\n\n**Command**\n\n```bash\n./magick -size 16x2 gradient: -type TrueColor -depth 8 -clahe 0x0! null:\n```\n\n**Output**\n\n<img width=\"1915\" height=\"818\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cfe44432-b429-49e4-8673-2ed55ba9a961\" />\n**Notes:** Without sanitizers, the process may terminate with just `Aborted` (still DoS).\n* * *\n## Impact\n  - Primary: Denial-of-Service — crash or sustained resource exhaustion (memory/cache thrash) when processing crafted parameters or small images via CLI or API. Attackers can trivially trigger via `clahe 0x0!` or by uploading very small images to services using ImageMagick.\n  - Secondary (theoretical): OOB memory accesses and memory corruption could potentially be combined with other vulnerabilities to achieve more severe outcomes; however, no reliable code execution was demonstrated from these PoCs alone.\n\n* * *\n\n## Suggested concrete patch snippets\n\nApply in `CLAHEImage()` after `tile_info` is computed but **before** any division/modulus/pointer arithmetic:\n\n```c\nif (exact_tiles_requested && (tile_info.width == 0 || tile_info.height == 0)) {\n  ThrowMagickException(exception, GetMagickModule(), OptionError,\n                       \"CLAHEInvalidTile\", \"%lux%lu\",\n                       (unsigned long) tile_info.width,\n                       (unsigned long) tile_info.height);\n  return (Image *) NULL;\n}\n\nif (!exact_tiles_requested) {\n  tile_info.width  = (tile_info.width  == 0) ? MagickMax((size_t)1, image->columns >> 3) : tile_info.width;\n  tile_info.height = (tile_info.height == 0) ? MagickMax((size_t)1, image->rows    >> 3) : tile_info.height;\n}\n\nif (tile_info.width == 0 || tile_info.height == 0) {\n  ThrowMagickException(exception, GetMagickModule(), OptionError,\n                       \"CLAHEInvalidTile\", \"%lux%lu\",\n                       (unsigned long) tile_info.width,\n                       (unsigned long) tile_info.height);\n  return (Image *) NULL;\n}\n\nssize_t tile_h_minus1 = (ssize_t)tile_info.height - 1;\nif (tile_h_minus1 < 0) {\n  ThrowMagickException(exception, GetMagickModule(), OptionError,\n                       \"CLAHEInvalidTile\", \"%lux%lu\",\n                       (unsigned long) tile_info.width,\n                       (unsigned long) tile_info.height);\n  return (Image *) NULL;\n}\np += (ptrdiff_t) clahe_info->width * tile_h_minus1;\n```\n\nNotes 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.\n\n* * *\n\n## Credit\n\n### Team Whys\n\n**Bug Hunting Master Program, HSpace/Findthegap**\n\n**Youngmin Kim**\nkunshim@naver.com\n\n**Woojin Park**\n\n[@jin-156](https://github.com/jin-156)\n[1203kids@gmail.com](mailto:1203kids@gmail.com)\n\n**Youngin Won**\n\n[@amethyst0225](https://github.com/amethyst0225)\n[youngin04@korea.ac.kr](mailto:youngin04@korea.ac.kr)\n\n**Siyeon Han**\n\n[@hanbunny](https://github.com/hanbunny)\n[kokosyeon@gmail.com](mailto:kokosyeon@gmail.com)\n\n**Shinyoung Won**\n\n[@yosiimich](yosimich123@gmail.com)\n[yosimich123@gmail.com](mailto:yosimich123@gmail.com)","format":"markdown","source":"jlsec"}],"published":"2026-07-30T16:02:27.435Z","modified":"2026-07-30T18:35:53.062Z","severity":{"scorer":"Julia Security Advisories","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H","score":5.5,"rating":"MEDIUM"},"severities":[{"scorer":"Julia Security Advisories","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H","score":5.5,"rating":"MEDIUM"}],"cwes":[],"affected":[{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"7.1.2011+0"}],"ecosystem":"Julia","package":"ImageMagick_jll","purl":"pkg:julia/ImageMagick_jll?uuid=c73af94c-d91f-53ed-93a7-00f77d67a9d7","source":"jlsec"}],"references":[{"url":"https://github.com/ImageMagick/ImageMagick/commit/7b47fe369eda90483402fcd3d78fa4167d3bb129","tags":["web"],"sources":["jlsec"]},{"url":"https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-wpp4-vqfq-v4hp","tags":["web"],"sources":["jlsec"]},{"url":"https://github.com/advisories/GHSA-wpp4-vqfq-v4hp","tags":["web"],"sources":["jlsec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-62594","tags":["web"],"sources":["jlsec"]}],"credits":["amethyst0225","hanbunny","jin-156","yosiimich"],"sources":[{"source":"jlsec","name":"Julia Security Advisories","id":"JLSEC-2026-928","url":"https://osv.dev/vulnerability/JLSEC-2026-928","licence":"CC-BY-4.0","modified":"2026-07-30T18:35:53.062Z"}],"updatedAt":"2026-11-25T22:56:26.291Z"}