@@ -5642,7 +5642,7 @@ wsrep_innobase_mysql_sort(
5642
5642
case MYSQL_TYPE_LONG_BLOB:
5643
5643
case MYSQL_TYPE_VARCHAR:
5644
5644
{
5645
- uchar tmp_str[REC_VERSION_56_MAX_INDEX_COL_LEN];
5645
+ uchar tmp_str[REC_VERSION_56_MAX_INDEX_COL_LEN] = {'\0'} ;
5646
5646
uint tmp_length = REC_VERSION_56_MAX_INDEX_COL_LEN;
5647
5647
5648
5648
/* Use the charset number to pick the right charset struct for
@@ -5681,11 +5681,11 @@ wsrep_innobase_mysql_sort(
5681
5681
} else {
5682
5682
/* strnxfrm will expand the destination string,
5683
5683
protocols < 3 truncated the sorted sring
5684
- protocols > 3 gets full sorted sring
5684
+ protocols >= 3 gets full sorted sring
5685
5685
*/
5686
5686
tmp_length = charset->coll->strnxfrm(
5687
5687
charset, str, buf_length,
5688
- str_length, tmp_str, tmp_length , 0);
5688
+ str_length, tmp_str, str_length , 0);
5689
5689
DBUG_ASSERT(tmp_length <= buf_length);
5690
5690
ret_length = tmp_length;
5691
5691
}
@@ -6228,6 +6228,7 @@ UNIV_INTERN
6228
6228
uint
6229
6229
wsrep_store_key_val_for_row(
6230
6230
/*===============================*/
6231
+ THD* thd,
6231
6232
TABLE* table,
6232
6233
uint keynr, /*!< in: key number */
6233
6234
char* buff, /*!< in/out: buffer for the key value (in MySQL
@@ -6242,25 +6243,33 @@ wsrep_store_key_val_for_row(
6242
6243
char* buff_start = buff;
6243
6244
enum_field_types mysql_type;
6244
6245
Field* field;
6245
-
6246
+ uint buff_space = buff_len;
6247
+
6246
6248
DBUG_ENTER("wsrep_store_key_val_for_row");
6247
6249
6248
6250
memset(buff, 0, buff_len);
6249
6251
*key_is_null = TRUE;
6250
6252
6251
6253
for (; key_part != end; key_part++) {
6254
+
6252
6255
uchar sorted[REC_VERSION_56_MAX_INDEX_COL_LEN] = {'\0'};
6253
6256
ibool part_is_null = FALSE;
6254
6257
6255
6258
if (key_part->null_bit) {
6256
- if (record[key_part->null_offset] &
6257
- key_part->null_bit) {
6258
- *buff = 1;
6259
- part_is_null = TRUE;
6259
+ if (buff_space > 0) {
6260
+ if (record[key_part->null_offset]
6261
+ & key_part->null_bit) {
6262
+ *buff = 1;
6263
+ part_is_null = TRUE;
6264
+ } else {
6265
+ *buff = 0;
6266
+ }
6267
+ buff++;
6268
+ buff_space--;
6260
6269
} else {
6261
- *buff = 0;
6270
+ fprintf (stderr, "WSREP: key truncated: %s\n",
6271
+ wsrep_thd_query(thd));
6262
6272
}
6263
- buff++;
6264
6273
}
6265
6274
if (!part_is_null) *key_is_null = FALSE;
6266
6275
@@ -6280,8 +6289,15 @@ wsrep_store_key_val_for_row(
6280
6289
key_len = key_part->length;
6281
6290
6282
6291
if (part_is_null) {
6283
- buff += key_len + 2;
6284
-
6292
+ true_len = key_len + 2;
6293
+ if (true_len > buff_space) {
6294
+ fprintf (stderr,
6295
+ "WSREP: key truncated: %s\n",
6296
+ wsrep_thd_query(thd));
6297
+ true_len = buff_space;
6298
+ }
6299
+ buff += true_len;
6300
+ buff_space -= true_len;
6285
6301
continue;
6286
6302
}
6287
6303
cs = field->charset();
@@ -6321,13 +6337,20 @@ wsrep_store_key_val_for_row(
6321
6337
REC_VERSION_56_MAX_INDEX_COL_LEN);
6322
6338
6323
6339
if (wsrep_protocol_version > 1) {
6324
- memcpy(buff, sorted, true_len);
6325
- /* Note that we always reserve the maximum possible
6326
- length of the true VARCHAR in the key value, though
6327
- only len first bytes after the 2 length bytes contain
6328
- actual data. The rest of the space was reset to zero
6329
- in the bzero() call above. */
6330
- buff += true_len;
6340
+ /* Note that we always reserve the maximum possible
6341
+ length of the true VARCHAR in the key value, though
6342
+ only len first bytes after the 2 length bytes contain
6343
+ actual data. The rest of the space was reset to zero
6344
+ in the bzero() call above. */
6345
+ if (true_len > buff_space) {
6346
+ fprintf (stderr,
6347
+ "WSREP: key truncated: %s\n",
6348
+ wsrep_thd_query(thd));
6349
+ true_len = buff_space;
6350
+ }
6351
+ memcpy(buff, sorted, true_len);
6352
+ buff += true_len;
6353
+ buff_space -= true_len;
6331
6354
} else {
6332
6355
buff += key_len;
6333
6356
}
@@ -6351,7 +6374,15 @@ wsrep_store_key_val_for_row(
6351
6374
key_len = key_part->length;
6352
6375
6353
6376
if (part_is_null) {
6354
- buff += key_len + 2;
6377
+ true_len = key_len + 2;
6378
+ if (true_len > buff_space) {
6379
+ fprintf (stderr,
6380
+ "WSREP: key truncated: %s\n",
6381
+ wsrep_thd_query(thd));
6382
+ true_len = buff_space;
6383
+ }
6384
+ buff += true_len;
6385
+ buff_space -= true_len;
6355
6386
6356
6387
continue;
6357
6388
}
@@ -6394,15 +6425,22 @@ wsrep_store_key_val_for_row(
6394
6425
mysql_type, cs->number, sorted, true_len,
6395
6426
REC_VERSION_56_MAX_INDEX_COL_LEN);
6396
6427
6397
- memcpy(buff, sorted, true_len);
6398
6428
6399
6429
/* Note that we always reserve the maximum possible
6400
6430
length of the BLOB prefix in the key value. */
6401
6431
if (wsrep_protocol_version > 1) {
6402
- buff += true_len;
6403
- } else {
6404
- buff += key_len;
6405
- }
6432
+ if (true_len > buff_space) {
6433
+ fprintf (stderr,
6434
+ "WSREP: key truncated: %s\n",
6435
+ wsrep_thd_query(thd));
6436
+ true_len = buff_space;
6437
+ }
6438
+ buff += true_len;
6439
+ buff_space -= true_len;
6440
+ } else {
6441
+ buff += key_len;
6442
+ }
6443
+ memcpy(buff, sorted, true_len);
6406
6444
} else {
6407
6445
/* Here we handle all other data types except the
6408
6446
true VARCHAR, BLOB and TEXT. Note that the column
@@ -6419,9 +6457,17 @@ wsrep_store_key_val_for_row(
6419
6457
key_len = key_part->length;
6420
6458
6421
6459
if (part_is_null) {
6422
- buff += key_len;
6460
+ true_len = key_len;
6461
+ if (true_len > buff_space) {
6462
+ fprintf (stderr,
6463
+ "WSREP: key truncated: %s\n",
6464
+ wsrep_thd_query(thd));
6465
+ true_len = buff_space;
6466
+ }
6467
+ buff += true_len;
6468
+ buff_space -= true_len;
6423
6469
6424
- continue;
6470
+ continue;
6425
6471
}
6426
6472
6427
6473
src_start = record + key_part->offset;
@@ -6459,12 +6505,18 @@ wsrep_store_key_val_for_row(
6459
6505
mysql_type, cs->number, sorted, true_len,
6460
6506
REC_VERSION_56_MAX_INDEX_COL_LEN);
6461
6507
6508
+ if (true_len > buff_space) {
6509
+ fprintf (stderr,
6510
+ "WSREP: key truncated: %s\n",
6511
+ wsrep_thd_query(thd));
6512
+ true_len = buff_space;
6513
+ }
6462
6514
memcpy(buff, sorted, true_len);
6463
6515
} else {
6464
6516
memcpy(buff, src_start, true_len);
6465
6517
}
6466
- buff += true_len;
6467
-
6518
+ buff += true_len;
6519
+ buff_space -= true_len;
6468
6520
}
6469
6521
}
6470
6522
@@ -9690,7 +9742,8 @@ ha_innobase::wsrep_append_keys(
9690
9742
ibool is_null;
9691
9743
9692
9744
len = wsrep_store_key_val_for_row(
9693
- table, 0, key, key_info->key_length, record0, &is_null);
9745
+ thd, table, 0, key, WSREP_MAX_SUPPORTED_KEY_LENGTH,
9746
+ record0, &is_null);
9694
9747
9695
9748
if (!is_null) {
9696
9749
rcode = wsrep_append_key(
@@ -9712,9 +9765,6 @@ ha_innobase::wsrep_append_keys(
9712
9765
KEY* key_info = table->key_info + i;
9713
9766
if (key_info->flags & HA_NOSAME) {
9714
9767
hasPK = true;
9715
- if (i != table->s->primary_key) {
9716
- wsrep_thd_set_PA_safe(thd, FALSE);
9717
- }
9718
9768
}
9719
9769
}
9720
9770
@@ -9745,7 +9795,8 @@ ha_innobase::wsrep_append_keys(
9745
9795
(!tab && referenced_by_foreign_key()))) {
9746
9796
9747
9797
len = wsrep_store_key_val_for_row(
9748
- table, i, key0, key_info->key_length,
9798
+ thd, table, i, key0,
9799
+ WSREP_MAX_SUPPORTED_KEY_LENGTH,
9749
9800
record0, &is_null);
9750
9801
if (!is_null) {
9751
9802
rcode = wsrep_append_key(
@@ -9755,7 +9806,6 @@ ha_innobase::wsrep_append_keys(
9755
9806
9756
9807
if (key_info->flags & HA_NOSAME || shared)
9757
9808
key_appended = true;
9758
-
9759
9809
}
9760
9810
else
9761
9811
{
@@ -9764,7 +9814,8 @@ ha_innobase::wsrep_append_keys(
9764
9814
}
9765
9815
if (record1) {
9766
9816
len = wsrep_store_key_val_for_row(
9767
- table, i, key1, key_info->key_length,
9817
+ thd, table, i, key1,
9818
+ WSREP_MAX_SUPPORTED_KEY_LENGTH,
9768
9819
record1, &is_null);
9769
9820
if (!is_null && memcmp(key0, key1, len)) {
9770
9821
rcode = wsrep_append_key(
0 commit comments