What are the potential security risks of using command-line programs for file extraction in PHP?

Using command-line programs for file extraction in PHP can pose security risks such as command injection attacks if user input is not properly sanitized. To mitigate this risk, it is important to validate and sanitize user input before passing it to the command-line program.

// Sanitize user input before using it in a command-line program
$user_input = escapeshellarg($_POST['file_name']);

// Use the sanitized input in the command-line program
$output = shell_exec("tar -xzvf $user_input");