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

Binlog Checksum is Zeroed by Zlib if Part of Event Data is Empty

    XMLWordPrintable

Details

    Description

      An existing binlog checksum can be overridden to 0 if writing a NULL payload when using Zlib for the computation. That is, calling into Zlib's crc32 with empty data initializes an incremental CRC computation to 0; from their documentation:

      If buf is Z_NULL, this function returns the required initial value for the crc.

      Looking into the binary logging code, we see that the checksum is computed as long as there is an existing checksum length:

      int Log_event_writer::write_data(const uchar *pos, size_t len)
      {
        DBUG_ENTER("Log_event_writer::write_data");
        if (checksum_len)
          crc= my_checksum(crc, pos, len);
       
        DBUG_RETURN((this->*encrypt_or_write)(pos, len));
      }
      

      Even if there is no payload to actually write. Conversely, in the actual encrypt_or_write function, we exit early if there is nothing to write.

      int Log_event_writer::encrypt_and_write(const uchar *pos, size_t len)
      {
        ...
        if (!len)
          return 0;
      

      This pattern should be extended into the write_data() to not (re)-compute the checksum if there is nothing to write.

      Attachments

        Issue Links

          Activity

            People

              bnestere Brandon Nesterenko
              bnestere Brandon Nesterenko
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.