php.net |  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
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: kocsismate@php.net Assigned:
Status: Closed Package: MySQLi related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2020-09-15 17:09 UTC] kocsismate@php.net
Description:
------------
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 https://github.com/php/php-src/blob/133035951565fcb869f7d0223db6e73adc7e2aea/ext/mysqlnd/mysqlnd_protocol_frame_codec.c#L118), 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')");

var_dump(mysqli_error_list($mysqli));
$mysqli->close();

Expected result:
----------------
The query should finish successfully

Actual result:
--------------
mysqli_error_list() prints the following:

array(1) {
  [0]=>
  array(3) {
    ["errno"]=>
    int(2006)
    ["sqlstate"]=>
    string(5) "HY000"
    ["error"]=>
    string(26) "MySQL server has gone away"
  }
}

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-15 17:13 UTC] kocsismate@php.net
-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] kocsismate@php.net
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:  https://github.com/php/php-src/pull/6136
Patch:      https://github.com/php/php-src/pull/6136.patch
 [2020-09-18 11:01 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=ecd9c42f9e54b53ea6917b2a28ae9e5a2c89c2fe
Log: Fix bug #80107: Handling of large compressed packets
 [2020-09-18 11:01 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Nov 23 20:01:23 2020 UTC