{"id":"JLSEC-2026-922","summary":"ImageMagick has Undefined Behavior (function-type-mismatch) in CloneSplayTree","details":"## Summary\n\n  - **Target:** ImageMagick (commit `ecc9a5eb456747374bae8e07038ba10b3d8821b3`)\n  - **Type:** Undefined Behavior (function-type-mismatch) in splay tree cloning callback\n  - **Impact:** Deterministic abort under UBSan (DoS in sanitizer builds). No crash in a non-sanitized build; likely low security impact.\n  - **Trigger:** Minimal **2-byte** input parsed via MagickWand, then coalescing.\n\n## Environment\n\nOS: macOS (Apple Silicon/arm64)\nHomebrew clang version 20.1.8\nTarget: arm64-apple-darwin24.5.0\nThread model: posix\nInstalledDir: /opt/homebrew/Cellar/llvm/20.1.8/bin\nConfiguration file: /opt/homebrew/etc/clang/arm64-apple-darwin24.cfg\nHomebrew ImageMagick: `magick -version` → `ImageMagick 7.1.2-0 Q16-HDRI aarch64`\npkg-config: `MagickWand-7.Q16HDRI` version `7.1.2`\nLibrary configure flags (capsule build):\n./configure --disable-shared --enable-static --without-modules --without-magick-plus-plus --disable-openmp --without-perl --without-x --with-png=yes --without-jpeg --without-tiff --without-xml --without-lqr --without-gslib\nHarness compile flags:\n-fsanitize=fuzzer,address,undefined -fno-omit-frame-pointer\npkg-config cflags/libs supplied:\n-I\u003c...\u003e/include/ImageMagick-7\n-DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32\nand linked against MagickWand-7.Q16HDRI and MagickCore-7.Q16HDRI\nSanitizer runtime:\nASan+UBSan defaults. Repro also with `UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1`\n\n## PoC\n\n  - **Bytes (hex):** `1c 02`\n  - **Base64:** `HAI=`\n  - **sha256 (optional):** \u003cfill in\u003e\n\n## Reproduction\n\nCreate PoC:\n\n`printf '\\x1c\\x02' \u003e poc.bin`\n\nOption A: libFuzzer harness\n\n  - Run once: `./harness_ImageMagick_... -runs=1 ./poc.bin`\n  - Expected: UBSan aborts with function-type-mismatch at `MagickCore/splay-tree.c:372:43`.\n\nOption B: standalone reproducer (C)\n\n  - Compile (ensure `PKG_CONFIG_PATH` points to your ImageMagick if needed):\n\n/opt/homebrew/opt/llvm/bin/clang -g -O1 -fsanitize=address,undefined $(/opt/homebrew/bin/pkg-config --cflags MagickWand-7.Q16HDRI) repro.c -o repro $(/opt/homebrew/bin/pkg-config --libs MagickWand-7.Q16HDRI)\n\n  - Run:\n\nUBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./repro ./poc.bin\nObserved output (excerpt)\nMagickCore/splay-tree.c:372:43: runtime error: call to function ConstantString through pointer to incorrect function type 'void *(*)(void *)'\nstring.c:680: note: ConstantString defined here\n#0 CloneSplayTree splay-tree.c:372\n#1 CloneImageProfiles profile.c:159\n#2 CloneImage image.c:832\n#3 CoalesceImages layer.c:269\n#4 MagickCoalesceImages magick-image.c:1665\n#5 main repro.c:XX\nRoot cause\nThe splay tree clone callback expects a function pointer of type `void *(*)(void *)`. ConstantString has a different signature (`char *ConstantString(const char *)`). Calling through the mismatched function type is undefined behavior in C and triggers UBSan’s function-type-mismatch.\nThe path is exercised during coalescing: CloneImage → CloneImageProfiles → CloneSplayTree.\nScope\nReproduces with a minimal, sanitizer-instrumented, PNG-enabled build and delegates disabled (policy.xml), suggesting the issue is in MagickCore rather than external delegates.\nSuggested fix (sketch)\nUse a wrapper that matches the expected callback prototype, or adjust the splay-tree callback typedef for const-correctness. For example:\nstatic void *CloneStringShim(const void *p) {\nreturn (void *) ConstantString((const char *) p);\n}\n\n/* When setting splay-tree clone_value, use CloneStringShim instead of ConstantString. */\n\nAlternatively, update the clone callback typedefs to use const void* consistently (and return void*) and ensure callers pass a correctly typed wrapper.\n\nArtifacts\nMinimised PoC: attached (poc.bin, 2 bytes; base64 HAI=)\nHarness source and exact build command (attached)\nFull UBSan trace (attached)\nCommit SHA and configure flags (above)\nCredits\nDiscovered by: Lumina Mescuwa\nMethod: libFuzzer + UBSan\nVerification\n\n  - UBSan build: Reproduces with `halt_on_error=1`; aborts at `MagickCore/splay-tree.c:372`.\n  - Non-sanitized Homebrew build (macOS arm64, clang 20.1.8): No crash; repro completes silently.","modified":"2026-07-30T18:35:33.334348163Z","published":"2026-07-30T16:02:27.435Z","upstream":["CVE-2025-55160","EUVD-2025-24566","GHSA-6hgw-6x87-578x"],"database_specific":{"sources":[{"html_url":"https://nvd.nist.gov/vuln/detail/CVE-2025-55160","database_specific":{"status":"Analyzed"},"id":"CVE-2025-55160","imported":"2026-07-30T14:08:44.239Z","modified":"2026-06-17T09:41:22.687Z","published":"2025-08-13T14:15:33.177Z","url":"https://services.nvd.nist.gov/rest/json/cves/2.0?cveId=CVE-2025-55160"},{"url":"https://api.github.com/advisories/GHSA-6hgw-6x87-578x","html_url":"https://github.com/advisories/GHSA-6hgw-6x87-578x","id":"GHSA-6hgw-6x87-578x","imported":"2026-07-30T14:09:18.675Z","modified":"2025-08-25T16:23:53Z","published":"2025-08-25T16:23:51Z"},{"published":"2025-08-13T14:00:53Z","url":"https://euvdservices.enisa.europa.eu/api/enisaid?id=EUVD-2025-24566","html_url":"https://euvd.enisa.europa.eu/vulnerability/EUVD-2025-24566","id":"EUVD-2025-24566","imported":"2026-07-30T14:08:56.036Z","modified":"2025-08-13T14:26:49Z"}],"license":"CC-BY-4.0"},"references":[{"type":"WEB","url":"https://github.com/ImageMagick/ImageMagick/security/advisories/GHSA-6hgw-6x87-578x"},{"type":"WEB","url":"https://github.com/advisories/GHSA-6hgw-6x87-578x"},{"type":"WEB","url":"https://github.com/dlemstra/Magick.NET/releases/tag/14.8.0"},{"type":"WEB","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-55160"}],"affected":[{"package":{"name":"ImageMagick_jll","ecosystem":"Julia","purl":"pkg:julia/ImageMagick_jll?uuid=c73af94c-d91f-53ed-93a7-00f77d67a9d7"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"7.1.2001+0"}]}],"database_specific":{"source":"https://github.com/JuliaLang/SecurityAdvisories.jl/tree/generated/osv/2026/JLSEC-2026-922.json"}}],"schema_version":"1.7.5","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L"}],"credits":[{"name":"mescuwa","contact":["https://github.com/mescuwa"],"type":"REPORTER"}]}