[MDEV-24770] COM_STMT_PREPARE wrong protocol behaviour when numerous columns Created: 2021-02-02  Updated: 2022-06-27

Status: Open
Project: MariaDB Server
Component/s: Protocol
Affects Version/s: 10.5
Fix Version/s: 10.5

Type: Bug Priority: Major
Reporter: Diego Dupin Assignee: Dmitry Shulga
Resolution: Unresolved Votes: 0
Labels: None


 Description   

COM_STMT_PREPARE protocol result permits only 2 bytes for returning columns number.

COM_STMT_PREPARE_OK format :

* int<1> 0x00 COM_STMT_PREPARE_OK header
* int<4> statement id
* int<2> number of columns in the returned result set (or 0 if statement does not return result set)
* int<2> number of prepared statement parameters ('?' placeholders)
* string<1> -not used-
* int<2> number of warnings

If number of columns is more than 65355, an error MUST be returned from server.
The actual implementation send unexpected data, resulting in wrong connectors state, and unusable connection.

Example:
prepare a query 'SELECT 1, 1, 1, 1, ...' with 100 000 value '1' .
result will be :

+--------------------------------------------------+
|  0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f |
+--------------------------------------------------+------------------+
| 0C 00 00 01 00 02 00 00  00 A0 86 00 00 00 00 00 | ................ |
+--------------------------------------------------+------------------+

number of columns = A0 86 = value 34 644 (100000 - 65356), not 100000
so connectors try to read 34 644 column definition packet, but there will be 65356 more.

Correction:
If number of column > 65355, an error has to be returned from server, like it's done when the number of parameters is too big (error "Prepared statement contains too many placeholders")


Generated at Thu Feb 08 09:32:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.