The vulnerability is an out-of-bounds write in Pillow's _imagingmorph C extension. The root cause is that the native apply function writes row edge pixels using outrow[0] = outrow[width - 1] = 0; without checking that the image width is positive. When a PPM/PGM file declares a width of 0 (which the PPM parser accepts because _open reads width/height via int(self._read_token()) with no lower-bound check), the expression outrow[width - 1] evaluates to outrow[-1], an out-of-bounds write that crashes the process (SEGV) and can cause memory corruption.
The fix (commit 18f7c0dfee93063c51db6ed0ca8c4da2999dcb64) adds an early-return guard if (!width || !height) in the native apply function, confirming that apply is the vulnerable function. The advisory also explicitly states that match() and get_on_pixels() use the same edge-indexing pattern, so they are also vulnerable to the same class of out-of-bounds access when given a zero-width image.
The vulnerable functions are:
apply (native C function in _imagingmorph.c) - directly performs the out-of-bounds write at line 81.
match (native C function) - uses the same edge-indexing pattern without a width guard.
get_on_pixels (native C function) - uses the same edge-indexing pattern without a width guard.
MorphOp.apply (Python method) - the public entry point that forwards a zero-width image to the vulnerable native code without validation.
For a C extension, the profiler/stack trace shows the bare function name (e.g., apply), as seen in the ASan output #0 apply src/_imagingmorph.c:81.