Bug #80731 [NEW]: escapeshellarg() silently corrupts "\xFF" on linux

From: Date: Thu, 11 Feb 2021 15:03:19 +0000
Subject: Bug #80731 [NEW]: escapeshellarg() silently corrupts "\xFF" on linux
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232060@lists.php.net to get a copy of this message
From: divinity76 at gmail dot com Operating system: Linux PHP version: 8.0.2 Package: *Data Exchange functions Bug Type: Bug Bug description:escapeshellarg() silently corrupts "\xFF" on linux Description: ------------ escapeshellarg() silently corrupts "\xFF" on linux Test script: --------------- <?php /** * quote arguments using linux escape rules, regardless of host OS * (eg, it will use linux escape rules even when running on Windows) * * @param string $arg * @throws \InvalidArgumentException if argument contains null bytes * @return string */ function linux_escapeshellarg(string $arg): string { if (false !== strpos($arg, "\x00")) { throw new \InvalidArgumentException("argument contains null bytes, it's impossible to escape null bytes!"); } return "'" . strtr($arg, [ "'" => "'\\''" ]) . "'"; } $cmd = "printf '%s' ".linux_escapeshellarg("\xFF"); var_dump(bin2hex(shell_exec($cmd))); // ^ works fine. $cmd = "printf '%s' ".escapeshellarg("\xFF"); var_dump(bin2hex(shell_exec($cmd))); // ^ is corrupted.. Expected result: ---------------- string(2) "ff" string(2) "ff" Actual result: -------------- string(2) "ff" string(0) "" -- Edit bug report at https://bugs.php.net/bug.php?id=80731&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80731&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80731&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80731&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80731&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80731&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80731&r=support Expected behavior: https://bugs.php.net/fix.php?id=80731&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80731&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80731&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80731&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80731&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80731&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80731&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80731&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80731&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80731&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80731&r=mysqlcfg

« previous php.bugs (#232060) next »