Bug #81049 [NEW]: PDO Sqlite in memory database ignores memory_limit
| From: | mvorisek at mvorisek dot cz | Date: | Wed, 19 May 2021 11:10:34 +0000 |
| Subject: | Bug #81049 [NEW]: PDO Sqlite in memory database ignores memory_limit | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-233894@lists.php.net to get a copy of this message | ||
From: mvorisek at mvorisek dot cz
Operating system: Windows
PHP version: 7.4.19
Package: PDO SQLite
Bug Type: Bug
Bug description:PDO Sqlite in memory database ignores memory_limit
Description:
------------
Currently, PDO Sqlite in memory database ignores memory_limit which is
dangerous as system's memory can be exhausted by a single script.
PDO Sqlite should allocate memory using PHP allocation routines so the
memory is counted and limited.
Test script:
---------------
<?php
var_dump(memory_get_usage());
var_dump(memory_get_usage(true));
echo "\n";
for ($i = 0; $i < 3; $i++) {
$db = new PDO('sqlite::memory:');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec('CREATE TABLE foo (bar TEXT)');
for ($j = 0; $j < 20; $j++) {
$db->exec("INSERT INTO foo (bar) VALUES ('" .
bin2hex(random_bytes(2 * 1024 * 1024)) . "')");
}
var_dump(memory_get_usage());
var_dump(memory_get_usage(true));
$db->exec('DROP TABLE foo');
$db = null;
var_dump(memory_get_usage());
var_dump(memory_get_usage(true));
echo "\n";
}
Expected result:
----------------
memory_get_usage includes memory allocated by sqlite and memory_limit is
honored
Actual result:
--------------
int(351144)
int(2097152)
int(351536)
int(2097152)
int(351176)
int(2097152)
int(351536)
int(2097152)
int(351176)
int(2097152)
int(351536)
int(2097152)
int(351176)
int(2097152)
--
Edit bug report at https://bugs.php.net/bug.php?id=81049&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81049&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81049&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81049&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81049&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81049&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81049&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81049&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81049&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81049&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81049&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81049&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81049&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81049&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81049&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81049&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81049&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81049&r=mysqlcfg