[MDEV-33283] Binlog Checksum is Zeroed by Zlib if Part of Event Data is Empty Created: 2024-01-19  Updated: 2024-01-22  Resolved: 2024-01-22

Status: Closed
Project: MariaDB Server
Component/s: Replication
Affects Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2, 11.3
Fix Version/s: 10.5.24, 10.6.17, 10.11.7, 11.0.5, 11.1.4, 11.2.3

Type: Bug Priority: Blocker
Reporter: Brandon Nesterenko Assignee: Brandon Nesterenko
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Issue split
split from MDEV-27666 User variable not parsed as geometry ... Closed

 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.



 Comments   
Comment by Brandon Nesterenko [ 2024-01-22 ]

Hi Elkin!

This is ready for review: PR-3016

Comment by Andrei Elkin [ 2024-01-22 ]

The GH PR is approved.

I believe we also need to report a ticket on incompatible behaviour of the maria's and Zlib functions and assign one to Serg.

Comment by Brandon Nesterenko [ 2024-01-22 ]

Pushed into 10.5 as 207c85783b2.

Generated at Thu Feb 08 10:37:46 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.