The vulnerability exists in the PostScript (PS, PS2, PS3) encoders within ImageMagick. The functions WritePSImage, WritePS2Image, and WritePS3Image were identified as vulnerable. These functions are responsible for generating PostScript output. The root cause of the vulnerability was the lack of input sanitization on the filename when it was used to create the '%%Title' field in the PostScript document header. An attacker could provide a specially crafted filename containing malicious PostScript commands. When the ImageMagick encoder processed this file, it would embed the unsanitized filename directly into the output file's header. A PostScript viewer or printer processing this malicious file would then execute the injected code. The patch introduces a new sanitization function, FilenameToTitle, which is now used to clean the filename before it is written to the PostScript header, thus mitigating the code injection vulnerability.