Bug #57074 mysql_store_result() fails if compression is enabled
Submitted: 28 Sep 2010 17:24 Modified: 6 Oct 2010 19:34
Reporter: Jan Kneschke Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.5.2, probably all versions, 5.0, 5.1, 5.6.99 OS:Any
Assigned to: CPU Architecture:Any

[28 Sep 2010 17:24] Jan Kneschke
Description:
Connector/C fails to decode packets correctly that are exactly 2^24-1 bytes long when compression is enabled leading to connection drops.

A query like 'SELECT repeat("a", 256 * 256 * 256 - 5)' generates a result that has the packet-sizes:

  01 00 00 01 01
  36 00 00 02 ..
  05 00 00 03 ..
  ff ff ff 04 ..
  00 00 00 05
  05 00 00 06 ..

when uncompressed. The query generates a row that is exactly 2^24-1 bytes long (a "full" packet with packet-length 0xff 0xff 0xff) which needs a "empty" packet with packet-len == 0 as terminator.

When compression is enabled this packet sequence leads to connection drops. The MySQL Server stays running.

It can be repeated with multiple "full" packets as long as they are followed by a "empty" packet.

It works fine if no compression is used.

How to repeat:
## set max packet big enough
$ echo 'set GLOBAL max_allowed_packet = 32 * 1024 * 1024;' | mysql

$ echo 'select repeat("a", 256 * 256 * 256 * 1 - 5); ' | mysql --max_allowed_packet=335544320 --compress > /dev/null
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query

$ echo 'select repeat("a", 256 * 256 * 256 * 2 - 11); ' | mysql --max_allowed_packet=335544320 --compress > /dev/null
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query

Suggested fix:
Fix long-packet handling with compression.
[28 Sep 2010 18:20] Sveta Smirnova
Thank you for the report.

Verified as described.
[28 Sep 2010 18:24] Valeriy Kravchuk
Verified also with current mysql-5.5 from bzr on Mac OS X:

macbook-pro:5.5 openxs$ echo 'set GLOBAL max_allowed_packet = 32 * 1024 * 1024;' | mysql bin/mysql -uroot test
-bash: mysql: command not found
macbook-pro:5.5 openxs$ echo 'set GLOBAL max_allowed_packet = 32 * 1024 * 1024;' | bin/mysql -uroot test
macbook-pro:5.5 openxs$ echo 'select repeat("a", 256 * 256 * 256 * 1 - 5); ' | bin/mysql -uroot test --max_allowed_packet=335544320 --compress > /dev/null
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query
macbook-pro:5.5 openxs$ echo 'select repeat("a", 256 * 256 * 256 * 2 - 11); ' | bin/mysql -uroot test --max_allowed_packet=335544320 --compress > /dev/null
ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query
macbook-pro:5.5 openxs$ echo 'select repeat("a", 256 * 256 * 256 - 100); ' | bin/mysql -uroot test --max_allowed_packet=335544320 --compress > /dev/null
macbook-pro:5.5 openxs$ bin/mysql --version
bin/mysql  Ver 14.14 Distrib 5.5.7-rc, for apple-darwin9.6.0 (i386) using readline 5.1
[28 Sep 2010 18:32] Mark Matthews
Connector/J is not affected. If there is a protocol change to fix this, please let all non-libmysql driver maintainers know. Thank you.
[28 Sep 2010 18:37] Peter Laursen
My God ... what a bug! Ggrrrrr! 

(everybody is welcome to comment on a bug - right?)
[6 Oct 2010 19:34] Konstantin Osipov
A duplicate of Bug#42503.