[php-src] PR #25529: Fix GH-25528: Phar::setSignatureAlgorithm(): OpenSSL signing reads a freed private key

From: Date: Tue, 17 Nov 2026 17:51:19 +0000
Subject: [php-src] PR #25529: Fix GH-25528: Phar::setSignatureAlgorithm(): OpenSSL signing reads a freed private key
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-40739@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/25529 Author: ArtUkrainskiy Fixes GH-25528 Phar::setSignatureAlgorithm() stores a pointer into its $privateKey argument in PHAR_G(openssl_privatekey) and doesn't copy the string. Every later write to the phar signs it again with that key. If the key string has been freed by then, signing reads freed memory. A file_get_contents() result passed directly is enough: ```php $phar->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents('private.pem')); $phar->addFromString('b.txt', 'b'); // signs with the freed key ``` This keeps a copy of the key and frees it when the key is replaced and in RSHUTDOWN. The test passes the key the same way, then allocates a string of the same size so the freed block gets reused. Without the fix it fails on a normal build too, with "unable to process private key". ext/phar tests pass, also with ASan and ZTS. The commit applies cleanly to 8.5, 8.6 and master.

« previous php.git-pulls (#40739) next »