Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-38374

nonsense code in wsrep_store_key_val_for_row()

    XMLWordPrintable

Details

    • Can result in hang or crash
    • Long blob prefix keys could cause a crash in galera.

    Description

      wsrep_store_key_val_for_row() in ha_innodb.cc has the following code

         if (mysql_type == MYSQL_TYPE_VARCHAR) {
           if (wsrep_protocol_version > 1) {
      ...
             if (true_len > buff_space) {
               WSREP_DEBUG (
                 "write set key truncated for: %s\n",
                 wsrep_thd_query(thd));
               true_len = buff_space;
             }
             memcpy(buff, sorted, true_len);
             buff += true_len;
             buff_space -= true_len;
           } else {
             buff += key_len;
           }
      

      which looks reasonable, but below it has

          } else if (mysql_type == MYSQL_TYPE_TINY_BLOB
            || mysql_type == MYSQL_TYPE_MEDIUM_BLOB
            || mysql_type == MYSQL_TYPE_BLOB
            || mysql_type == MYSQL_TYPE_LONG_BLOB
            || mysql_type == MYSQL_TYPE_GEOMETRY) {
      ...
            if (wsrep_protocol_version > 1) {
              if (true_len > buff_space) {
                fprintf (stderr,
                   "WSREP: key truncated: %s\n",
                   wsrep_thd_query(thd));
                true_len = buff_space;
              }
              buff       += true_len;
              buff_space -= true_len;
            } else {
              buff += key_len;
            }
            memcpy(buff, sorted, true_len);
      

      which makes no sense — first it moves buff and then copies? Clearly a copy-paste mistake.

      It causes crashes too:

      source include/galera_cluster.inc;
      source include/have_innodb.inc;
      create table t1 (
          id int auto_increment primary key,
          blob_data longblob not null,
          unique key idx_blob_prefix (blob_data(3072))
      ) engine=innodb;
      insert into t1 (blob_data) values ('a');
      update t1 set blob_data = repeat('x', 4000) where id = 1;
      

      Attachments

        Activity

          People

            serg Sergei Golubchik
            serg Sergei Golubchik
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.