The vulnerability lies in the memory management within the bilateral blur functionality of ImageMagick. The analysis of the patch in MagickCore/effect.c reveals that the function AcquireBilateralTLS allocates an array of pointers (weights) of size number_threads + 1, but the original code only initialized number_threads elements using memset. This left the last pointer in the array uninitialized.
If a subsequent memory allocation within the loop of AcquireBilateralTLS fails, the cleanup function DestroyBilateralTLS is called. DestroyBilateralTLS iterates through the weights array to free the allocated memory. Since the last element was never initialized, this results in an attempt to free an invalid pointer, leading to a crash and a denial-of-service vulnerability.
The BilateralBlurImage function is the entry point that utilizes this faulty allocation logic, making it a key part of the exploitation path. The patch corrects the memset size to (number_threads + 1) * sizeof(*weights), ensuring all allocated pointers are properly null-initialized before use, thus mitigating the vulnerability.