|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80107 mysqli_query() fails for ~16 MB long query when compression is enabled
Submitted: 2020-09-15 17:09 UTC Modified: 2020-09-15 17:13 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned:
Status: Closed Package: MySQLi related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2020-09-15 17:09 UTC]
We noticed that mysqli_query() fails when we want to execute a long query (around 16 MB) with compression enabled, using MYSQLI_CLIENT_CONNECTION. A few details:

- mysqli is compiled with mysqlnd
- The issue is reproducible both on PHP 7.4 and current master
- The issue is reproducible both with MySQL 5.7 and 8.0
- The "max_allowed_packet" MySQL settings don't affect the bug
- The query fails when at least 16 777 174 bytes long with "MySQL server has gone away"
- The query hangs forever when exactly 16 777 173 bytes long
- The query works when less than 16 777 173 bytes long

I tried to find some suspicious signs (e.g. by enabling the branch inside "WHEN_WE_NEED_TO_CHECK_WHETHER_COMPRESSION_WORKS_CORRECTLY" in, but decompression was working according to the debug output.

Test script:
$mysqli = mysqli_init();
$result = $mysqli->real_connect($host, $user, $passwd, $db, $port, $socket, MYSQLI_CLIENT_COMPRESS);

// Create test table
$mysqli->query("DROP TABLE IF EXISTS test");
$mysqli->query("CREATE TABLE test (`blob` LONGBLOB NOT NULL)");

// Insert a long string
$data = str_repeat("x", 16 * 1024 * 1024);
$mysqli->query("INSERT INTO $db.test(`blob`) VALUE ('$data')");


Expected result:
The query should finish successfully

Actual result:
mysqli_error_list() prints the following:

array(1) {
  array(3) {
    string(5) "HY000"
    string(26) "MySQL server has gone away"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-15 17:13 UTC]
-Summary: mysqli_query() fails for big query when compression is enabled +Summary: mysqli_query() fails for ~16 MB long query when compression is enabled
 [2020-09-15 17:18 UTC]
The following pull request has been associated:

Patch Name: Bug #80107 Add test for mysqli_query() fails for ~16 MB long query when compression is enabled
On GitHub:
 [2020-09-18 11:01 UTC]
Automatic comment on behalf of
Log: Fix bug #80107: Handling of large compressed packets
 [2020-09-18 11:01 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 02:01:28 2024 UTC