Bug #81142 [NEW]: PHP 7.3+ memory leak when unserialize() is used on an associative array
| From: | jnelson at archive dot org | Date: | Tue, 15 Jun 2021 17:27:48 +0000 |
| Subject: | Bug #81142 [NEW]: PHP 7.3+ memory leak when unserialize() is used on an associative array | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-234417@lists.php.net to get a copy of this message | ||
From: jnelson at archive dot org
Operating system:
PHP version: 7.3.28
Package: Arrays related
Bug Type: Bug
Bug description:PHP 7.3+ memory leak when unserialize() is used on an associative array
Description:
------------
As seen here: https://3v4l.org/KPJ62#focus=eol
This program loops thousands of times calling serialize() and
unserialize() on associative arrays with a string key and an integer
value without holding long-term references to any of the data.
Prior to 7.3, this program would peak at a few hundred KB. With 7.3.0
forward, this program consumes megabytes.
The two flags at the top of the program can be used to confirm (a) the
memory leak only occurs with associative arrays, and (b) it's caused by
unserialize() and not serialize().
Test script:
---------------
The core of the linked program to repro the problem:
function load($str) {
$php = serialize([ $str => 1 ]);
unserialize($php);
}
for ($ctr = 0; $ctr < 50000; $ctr++)
load("foo_$ctr");
echo memory_get_peak_usage();
Expected result:
----------------
Prior to 7.3.0, my linked program produces this output (or similar
numbers):
Usage: 377.99 K
Peak: 414.33 K
Actual result:
--------------
With 7.3.0 to 8.0.3, the numbers look like this:
Usage: 4.73 M
Peak: 5.34 M
--
Edit bug report at https://bugs.php.net/bug.php?id=81142&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81142&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81142&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81142&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81142&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81142&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81142&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81142&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81142&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81142&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81142&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81142&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81142&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81142&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81142&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81142&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81142&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81142&r=mysqlcfg