GD versions before 2.86 for Perl allow OS command injection and file overwrite via a 2-arg open() of filename arguments in _make_filehandle. GD::Image::_make_filehandle opens a filename argument with Perl's 2-arg open(), so a filename that begins or ends with a pipe ("| cmd", "cmd |") or begins with a redirect ("> path", ">> path") is run as a command or redirect rather than opened as a file. _make_filehandle is the single open path behind every filename-accepting constructor (new, newFromPng, newFromJpeg, and the rest); the in-memory *Data variants do not open a path and are unaffected. Any caller that forwards untrusted input to one of these constructors as a pathname can run an arbitrary command or truncate a file under the process UID.
The GD::Image::_make_filehandle function opens the passed filename using Perl's two-argument form of open(). This form of the interpreter allows special handling of filenames starting or ending with a pipe character ('| cmd', 'cmd |') as shell commands to execute, and filenames starting with a redirection character ('> path', '>> path') as output redirections. Since _make_filehandle is the only file handling path for all constructors accepting filenames (new, newFromPng, newFromJpeg and others), any application passing untrusted input to these constructors is vulnerable. Variants operating on in-memory data (*Data) do not use file path opening and are not affected by this issue.
An attacker who can control the filename argument passed to vulnerable GD constructors can execute arbitrary system commands with the process privileges (UID) or overwrite (truncate) any file accessible to that process.
The GD module for Perl should be updated to version 2.86 or later, which includes a patch replacing the unsafe 2-arg open() with a secure 3-arg open(). The patch is available in the vendor references on GitHub and in the CPAN repository (metacpan.org). Until the update is applied, all untrusted input passed as filenames to GD constructors must be rigorously validated and rejected.
GD module for Perl in versions before 2.86
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H