php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79881 Memory leak in openssl_pkey_get_public()
Submitted: 2020-07-21 23:11 UTC Modified: 2020-07-22 08:05 UTC
From: nikita dot korzhitskii at liu dot se Assigned: nikic (profile)
Status: Closed Package: OpenSSL related
PHP Version: 7.3 OS: Linux, macOS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikita dot korzhitskii at liu dot se
New email:
PHP Version: OS:

 

 [2020-07-21 23:11 UTC] nikita dot korzhitskii at liu dot se
Description:
------------
Memory seems to be leaking, when extracting public keys from x509 certificates with openssl_pkey_get_public(). Resources do not free automatically, with openssl_pkey_free(), unset(), or null-assignment. 

The leakage is observed on 
PHP 7.1.23 macOS Darwin Kernel Version 18.7.0 + LibreSSL 2.2.7/2.6.5, 
PHP 7.2.24-0ubuntu0.18.04.6 + OpenSSL/1.1.1
PHP 8.0.0-dev Ubuntu + OpenSSL/1.1.1

The test script is provided.

Test script:
---------------
https://gist.github.com/nikita-kun/88b80583a4d12230910040cf2cd3031d

Expected result:
----------------
Constant memory usage

Actual result:
--------------
Memory usage, real: 2097152
Memory usage, real: 4194304
Memory usage, real: 6295552
...
Memory usage, real: 106958848
Memory usage, real: 109056000

Warning: openssl_x509_read(): Supplied parameter cannot be coerced into an X509 certificate! in ./php-src/memleak.php on line 38

Fatal error: Uncaught TypeError: openssl_pkey_free(): Argument #1 ($key) must be of type resource, bool given in ./php-src/memleak.php:41
Stack trace:
#0 ./php-src/memleak.php(41): openssl_pkey_free(false)
#1 ./php-src/memleak.php(56): fastLeakage()
#2 {main}
  thrown in ./php-src/memleak.php on line 41
Killed

OR

"Fatal error: Allowed memory ... exhausted".

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-22 07:46 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2020-07-22 08:05 UTC] nikic@php.net
-Summary: Memory leak, openssl_pkey_get_public() +Summary: Memory leak in openssl_pkey_get_public() -Status: Verified +Status: Assigned -PHP Version: master-Git-2020-07-21 (Git) +PHP Version: 7.3 -Assigned To: +Assigned To: nikic
 [2020-07-22 08:21 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=657a832a77d3c0759dce095b619aa16cd5c360ce
Log: Fixed bug #79881
 [2020-07-22 08:21 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC