[php-src] Issue #13054: escapeshellarg() strips off bytes which are not valid characters (leading to file not found errors)

From: Date: Sat, 30 Dec 2023 13:41:37 +0000
Subject: [php-src] Issue #13054: escapeshellarg() strips off bytes which are not valid characters (leading to file not found errors)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246155@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/13054 Author: ohyeaah ### Description It seems escapeshellarg() strips off bytes which are >= 128 probably because they are not valid UTF-8 characters. Because it's not possible to provide an encoding to escapeshellarg() and this behaviour is not [documented](https://www.php.net/manual/en/function.escapeshellarg.php) I think it's a bug. Also if this is expected behaviour then which function could be used instead? There is no other function which could do this. Please note that the code example runs on Linux only because Windows (probably) doesn't have the cat command. Also I tested this on Linux only. Also note it's not necessary to close the php tag. ```php <?php $fname = "asdf.txt".chr(128); file_put_contents($fname, "hey!"); $cmd = "cat ".escapeshellarg($fname); echo "cmd: $cmd\n"; passthru($cmd); ``` Resulted in this output: ``` cmd: cat 'asdf.txt' cat: asdf.txt: No such file or directory ``` But I expected this output instead: ``` cmd: cat 'asdf.txt'$'\200' hey! ``` ### PHP Version PHP 8.2.7 (cli) (built: Jun 9 2023 19:37:27) (NTS) ### Operating System Debian GNU/Linux 12 (bookworm)

« previous php.bugs (#246155) next »