[MDEV-17589] Stack-buffer-overflow with indexed varchar (utf8) field Created: 2018-11-01 Updated: 2018-12-19 Resolved: 2018-12-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2, 10.3 |
| Fix Version/s: | 10.1.38, 10.0.38, 10.2.20, 10.3.12 |
| Type: | Bug | Priority: | Major |
| Reporter: | Alice Sherepa | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
10.2 abcd09c95a49d02bf136a21d62d38a2, built with -DWITH_ASAN=ON -DCMAKE_BUILD_TYPE=Debug
|
| Comments |
| Comment by Varun Gupta (Inactive) [ 2018-11-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
#define MAX_KEY_LENGTH 3072 /* max possible key */ For field v1 (charset utf8) So the total length for the lookup key would be 3075 keys and
We have a check in mysql_prepare_create_table where we check
but the key_part_length does not include the length and NULL bytes | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-11-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
Possible solutionsSolution #1: is to count NULL-bytes and length bytes in the key_part_length in mysql_prepare_create_table().It will cause a problem that some table definitions that were created earlier will no longer be accepted. Solution #2: is to keep the limits on key size the same, but increase key buffer space.Introduce a new constant as MAX_KEY_LENGTH_FOR_LOOKUP which would take into account the LENGTH and NULL BYTES. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
For Solution #2, maybe, increase MAX_KEY_LENGTH (as there are many places that use "char buffer[MAX_KEY_LENGTH]"), and change the mysql_prepare_create_table() to use some different constant which will still be 3072. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2018-11-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Yeah, I'd also suggest to increase MAX_KEY_LENGTH and fix the mysql_prepare_create_table() check. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-11-05 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
patch | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Review input http://lists.askmonty.org/pipermail/commits/2018-November/013068.html | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
varun also please change MDEV_ to MDEV in the commit message so that grepping for commit can find it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2018-11-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
For the record, on Windows it looks like this:
| ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-11-12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Patch | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2018-11-14 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
The patch is ok, see the question about the version in the email | ||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2018-12-18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Backported |