Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions libs/mysql/binlog/event/binlog_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ bool Log_event_footer::event_checksum_test(unsigned char *event_buf,
flags = le16toh(flags);
if (flags & LOG_EVENT_BINLOG_IN_USE_F)
event_buf[FLAGS_OFFSET] &= ~LOG_EVENT_BINLOG_IN_USE_F;
/*
The only algorithm currently is CRC32. Zero indicates
the binlog file is checksum-free *except* the FD-event.
*/
/*
The only algorithm currently is CRC32. Zero indicates
the binlog file is checksum-free *except* the FD-event.
*/
#ifndef NDEBUG
BAPI_ASSERT(fd_alg == BINLOG_CHECKSUM_ALG_CRC32 || fd_alg == 0);
#endif
Expand Down Expand Up @@ -232,7 +232,12 @@ bool Log_event_footer::event_checksum_test(unsigned char *event_buf,
}

Log_event_header::Log_event_header(Event_reader &reader)
: data_written(0), log_pos(0), m_is_valid(false) {
: type_code(ENUM_END_EVENT),
unmasked_server_id(0),
data_written(0),
log_pos(0),
flags(0),
m_is_valid(false) {
BAPI_ENTER("Log_event_header::Log_event_header(Event_reader &)");

/*
Expand Down
7 changes: 6 additions & 1 deletion libs/mysql/binlog/event/binlog_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,12 @@ class Log_event_header {
typedef unsigned char Byte;

explicit Log_event_header(Log_event_type type_code_arg = ENUM_END_EVENT)
: type_code(type_code_arg), data_written(0), log_pos(0), flags(0) {
: type_code(type_code_arg),
unmasked_server_id(0),
data_written(0),
log_pos(0),
flags(0),
m_is_valid(true) {
when.tv_sec = 0;
when.tv_usec = 0;
}
Expand Down
4 changes: 4 additions & 0 deletions libs/mysql/binlog/event/rows_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,12 @@ Table_map_event::Optional_metadata_fields::Optional_metadata_fields(

Rows_event::Rows_event(const char *buf, const Format_description_event *fde)
: Binary_log_event(&buf, fde),
m_type(ENUM_END_EVENT),
m_table_id(0),
m_flags(0),
m_width(0),
n_bits_len(0),
var_header_len(0),
columns_before_image(0),
columns_after_image(0),
row(0) {
Expand Down
4 changes: 4 additions & 0 deletions libs/mysql/binlog/event/rows_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,12 @@ class Rows_event : public Binary_log_event {
*/
explicit Rows_event(Log_event_type type_arg)
: Binary_log_event(type_arg),
m_type(type_arg),
m_table_id(0),
m_flags(0),
m_width(0),
n_bits_len(0),
var_header_len(0),
columns_before_image(0),
columns_after_image(0),
row(0) {}
Expand Down
1 change: 1 addition & 0 deletions unittest/gunit/binlogevents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES(SYSTEM ${GMOCK_INCLUDE_DIRS})

# Add tests
SET(TESTS
event_initialization
gno_intervals
grow_calculator
gtids
Expand Down
62 changes: 62 additions & 0 deletions unittest/gunit/binlogevents/event_initialization-t.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Copyright (c) 2026, Oracle and/or its affiliates.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.

This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with the
program or referenced in the documentation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */

#include <array>

#include <gtest/gtest.h>

#include "mysql/binlog/event/binlog_event.h"
#include "mysql/binlog/event/control_events.h"
#include "mysql/binlog/event/rows_event.h"

namespace mysql::binlog::event::unittests {

TEST(EventInitializationTest, LogEventHeaderDefaults) {
Log_event_header header;

EXPECT_EQ(0, header.when.tv_sec);
EXPECT_EQ(0, header.when.tv_usec);
EXPECT_EQ(ENUM_END_EVENT, header.type_code);
EXPECT_EQ(0U, header.unmasked_server_id);
EXPECT_EQ(0U, header.data_written);
EXPECT_EQ(0U, header.log_pos);
EXPECT_EQ(0U, header.flags);
EXPECT_TRUE(header.get_is_valid());
}

TEST(EventInitializationTest, MalformedRowsEventHasDeterministicState) {
const Format_description_event fde(BINLOG_VERSION, "8.0.0");
std::array<char, LOG_EVENT_MINIMAL_HEADER_LEN> buffer{};
buffer[EVENT_TYPE_OFFSET] = static_cast<char>(WRITE_ROWS_EVENT);
buffer[EVENT_LEN_OFFSET] = static_cast<char>(buffer.size());

Rows_event event(buffer.data(), &fde);

EXPECT_FALSE(event.header()->get_is_valid());
EXPECT_EQ(0U, event.get_table_id());
EXPECT_EQ(0U, event.get_flags());
EXPECT_EQ(0U, event.get_width());
EXPECT_EQ(0U, event.get_null_bits_len());
}

} // namespace mysql::binlog::event::unittests
Loading