diff --git a/libs/mysql/binlog/event/binlog_event.cpp b/libs/mysql/binlog/event/binlog_event.cpp index 1f9edc9012a0..4a0be0db303a 100644 --- a/libs/mysql/binlog/event/binlog_event.cpp +++ b/libs/mysql/binlog/event/binlog_event.cpp @@ -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 @@ -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 &)"); /* diff --git a/libs/mysql/binlog/event/binlog_event.h b/libs/mysql/binlog/event/binlog_event.h index 1036d5e781b6..1d11fd8001e7 100644 --- a/libs/mysql/binlog/event/binlog_event.h +++ b/libs/mysql/binlog/event/binlog_event.h @@ -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; } diff --git a/libs/mysql/binlog/event/rows_event.cpp b/libs/mysql/binlog/event/rows_event.cpp index cf326894dfd5..544db1c46a0a 100644 --- a/libs/mysql/binlog/event/rows_event.cpp +++ b/libs/mysql/binlog/event/rows_event.cpp @@ -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) { diff --git a/libs/mysql/binlog/event/rows_event.h b/libs/mysql/binlog/event/rows_event.h index 34ef92cc4495..a7750a66970f 100644 --- a/libs/mysql/binlog/event/rows_event.h +++ b/libs/mysql/binlog/event/rows_event.h @@ -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) {} diff --git a/unittest/gunit/binlogevents/CMakeLists.txt b/unittest/gunit/binlogevents/CMakeLists.txt index 097ea5047a0d..2e0056e70cf2 100644 --- a/unittest/gunit/binlogevents/CMakeLists.txt +++ b/unittest/gunit/binlogevents/CMakeLists.txt @@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES(SYSTEM ${GMOCK_INCLUDE_DIRS}) # Add tests SET(TESTS + event_initialization gno_intervals grow_calculator gtids diff --git a/unittest/gunit/binlogevents/event_initialization-t.cc b/unittest/gunit/binlogevents/event_initialization-t.cc new file mode 100644 index 000000000000..fc3d3b073508 --- /dev/null +++ b/unittest/gunit/binlogevents/event_initialization-t.cc @@ -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 + +#include + +#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 buffer{}; + buffer[EVENT_TYPE_OFFSET] = static_cast(WRITE_ROWS_EVENT); + buffer[EVENT_LEN_OFFSET] = static_cast(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