Bug #70529 [NEW]: mcrypt_decrypt() call sometime results in "String is not zero-terminated" error

From: Date: Fri, 18 Sep 2015 22:13:05 +0000
Subject: Bug #70529 [NEW]: mcrypt_decrypt() call sometime results in "String is not zero-terminated" error
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196079@lists.php.net to get a copy of this message
From: yohgaki Operating system: Linux PHP version: 7.0Git-2015-09-18 (Git) Package: mcrypt related Bug Type: Bug Bug description:mcrypt_decrypt() call sometime results in "String is not zero-terminated" error Description: ------------ While I was looking into this bug https://bugs.php.net/bug.php?id=70520 I found mcrypt_decrypt() sometimes raises "String is not zero-terminated" error. It seems mcrypt_decrypt() returns broken data sometimes also. It makes session decode fail on occasion. Warning: String is not zero-terminated (�J?w�fr, �:v�handler) (source: /home/yohgaki/git/oss/php.net/php-src/Zend/zend_execute.c:2061) in /home/yohgaki/workspace/ext/git/oss/php.net/php-src/tt2.php on line 20 Warning: session_start(): Failed to decode session object. Session has been destroyed in /home/yohgaki/workspace/ext/git/oss/php.net/php-src/tt2.php on line 38 Tested by CLI server. If I don't use mcrypt_decrypt/encrypt(), the test code will not raise errors. Test script: --------------- <?php ob_start(); error_reporting(E_ALL | E_STRICT); ini_set('session.save_path', '/tmp'); ini_set('display_errors', true); class EncryptedSessionHandler extends SessionHandler { private $key; public function __construct($key) { $this->key = $key; } public function read($id) { $data = parent::read($id); return mcrypt_decrypt(MCRYPT_3DES, $this->key, $data, MCRYPT_MODE_ECB); //return $data; } public function write($id, $data) { $data = mcrypt_encrypt(MCRYPT_3DES, $this->key, $data, MCRYPT_MODE_ECB); return parent::write($id, $data); } } ini_set('session.save_handler', 'files'); $key = substr(sha1(random_bytes(24)), 0, 24); $handler = new EncryptedSessionHandler($key); session_set_save_handler($handler, true); echo '<pre>'; session_start(); $_SESSION['key'] = 1234; var_dump($_SESSION); echo session_id() . PHP_EOL; session_regenerate_id(true); echo session_id() . PHP_EOL; -- Edit bug report at https://bugs.php.net/bug.php?id=70529&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70529&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70529&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70529&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70529&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70529&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70529&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70529&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70529&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70529&r=support Expected behavior: https://bugs.php.net/fix.php?id=70529&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70529&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70529&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70529&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70529&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70529&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70529&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70529&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70529&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70529&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70529&r=mysqlcfg

« previous php.bugs (#196079) next »