Bug->Req #81049 [Opn]: PDO Sqlite in memory database ignores memory_limit

From: Date: Wed, 19 May 2021 11:37:14 +0000
Subject: Bug->Req #81049 [Opn]: PDO Sqlite in memory database ignores memory_limit
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233895@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81049&edit=1 ID: 81049 Updated by: cmb@php.net Reported by: mvorisek at mvorisek dot cz Summary: PDO Sqlite in memory database ignores memory_limit Status: Open -Type: Bug +Type: Feature/Change Request Package: PDO SQLite Operating System: Windows PHP Version: 7.4.19 Block user comment: N Private report: N New Comment: > PDO Sqlite should allocate memory using PHP allocation routines SQLite3 offers custom allocators[1] as of 3.6.10, and PHP 7.4 already requires 3.7.5, so this looks possible and would make sense. I don't think not using ZendMM here qualifies as bug, though, since this is quite common for many extensions interfacing with external libraries. Thus, changing to feature request. Note that ext/sqlite3 likely has the same issue. [1] <https://www.sqlite.org/c3ref/mem_methods.html> Previous Comments: ------------------------------------------------------------------------ [2021-05-19 11:10:34] mvorisek at mvorisek dot cz 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 this bug report at https://bugs.php.net/bug.php?id=81049&edit=1

« previous php.bugs (#233895) next »