[MDEV-11833] JSON functions don't seem to respect max_allowed_packet Created: 2017-01-18  Updated: 2017-03-15  Resolved: 2017-03-14

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.2
Fix Version/s: 10.2.5

Type: Bug Priority: Major
Reporter: Andrii Nikitin (Inactive) Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None

Sprint: 10.2.5-1

 Description   

MariaDB [test]> \W
Show warnings enabled.
MariaDB [test]> set @a= json_quote(json_array(repeat('a',1024),repeat('a',1024))); select length(@a);
Query OK, 0 rows affected (0.00 sec)
 
+------------+
| length(@a) |
+------------+
|       2062 |
+------------+
1 row in set (0.00 sec)
 
MariaDB [test]> show variables like 'max_allowed_packet';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_allowed_packet | 1024  |
+--------------------+-------+
1 row in set (0.00 sec)

Similar behavior of other functions:

MariaDB [test]> select concat(repeat('a',1024),repeat('a',1024));
+-------------------------------------------+
| concat(repeat('a',1024),repeat('a',1024)) |
+-------------------------------------------+
| NULL                                      |
+-------------------------------------------+
1 row in set, 1 warning (0.00 sec)
 
Warning (Code 1301): Result of concat() was larger than max_allowed_packet (1024) - truncated

While this example looks artificial , it may cause serious stability issues in many scenarios on production (unintentionally, e.g. because of bug in client software or used by attacker to impact performance / stability) - so I put 'Major' priority here, but I am OK with 'Minor' priority if such is justified.



 Comments   
Comment by Elena Stepanova [ 2017-01-18 ]

I don't think the example is exceedingly artificial. In reality, JSON texts can probably be quite long, so they can exceed max_allowed_packet.
In MySQL it works as expected:

MySQL 5.7

MySQL [test]> select json_quote(json_array(repeat('a',1024),repeat('a',1024)));
+-----------------------------------------------------------+
| json_quote(json_array(repeat('a',1024),repeat('a',1024))) |
+-----------------------------------------------------------+
| NULL                                                      |
+-----------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
 
MySQL [test]> show warnings;
+---------+------+------------------------------------------------------------------------------+
| Level   | Code | Message                                                                      |
+---------+------+------------------------------------------------------------------------------+
| Warning | 1301 | Result of json_array() was larger than max_allowed_packet (1024) - truncated |
+---------+------+------------------------------------------------------------------------------+
1 row in set (0.00 sec)
 
MySQL [test]> select @@version;
+--------------+
| @@version    |
+--------------+
| 5.7.17-debug |
+--------------+
1 row in set (0.00 sec)

Comment by Alexey Botchkov [ 2017-03-14 ]

http://lists.askmonty.org/pipermail/commits/2017-March/010858.html

Generated at Thu Feb 08 07:53:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.