-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-40646: Undersized Table_map Metadata can Crash Slave #5524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bnestere
wants to merge
2
commits into
10.6
Choose a base branch
from
10.6-MDEV-40646
base: 10.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
mysql-test/suite/rpl/r/rpl_table_map_metadata_underflow.result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| include/master-slave.inc | ||
| [connection master] | ||
| connection slave; | ||
| call mtr.add_suppression("Found invalid event in binary log"); | ||
| call mtr.add_suppression("Relay log read failure: Could not parse relay log event entry"); | ||
| # | ||
| # Initialize test data | ||
| # | ||
| connection slave; | ||
| include/stop_slave.inc | ||
| CHANGE MASTER TO MASTER_USE_GTID=slave_pos; | ||
| include/start_slave.inc | ||
| connection master; | ||
| create table t1 (c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int,c17 int,c18 int,c19 int,c20 int,c21 int,c22 int,c23 int,c24 int); | ||
| insert into t1 (c1) values (0); | ||
| include/save_master_gtid.inc | ||
| connection slave; | ||
| include/sync_with_master_gtid.inc | ||
| connection master; | ||
| set @saved_dbug= @@global.debug_dbug; | ||
| # | ||
| # Test Case: a Table_map declaring more metadata than it carries | ||
| # | ||
| connection master; | ||
| set @@global.debug_dbug= "+d,binlog_sender_undersized_table_map_metadata"; | ||
| connection slave; | ||
| include/stop_slave.inc | ||
| include/start_slave.inc | ||
| connection master; | ||
| insert into t1 (c1) values (1); | ||
| connection slave; | ||
| # Waiting for the SQL thread to reject the malformed Table_map | ||
| include/wait_for_slave_sql_error.inc [errno=1594] | ||
| # Ensure the event was rejected before its metadata was decoded | ||
| include/assert_grep.inc [The SQL thread reported an invalid event] | ||
| # | ||
| # Recover: discard the poisoned relay log and re-fetch a clean copy | ||
| # | ||
| connection master; | ||
| set @@global.debug_dbug= @saved_dbug; | ||
| connection slave; | ||
| include/stop_slave_io.inc | ||
| include/start_slave.inc | ||
| # | ||
| # Ensure replication works after the invalid event | ||
| # | ||
| connection master; | ||
| insert into t1 (c1) values (2); | ||
| include/save_master_gtid.inc | ||
| connection slave; | ||
| include/sync_with_master_gtid.inc | ||
| include/diff_tables.inc [master:t1,slave:t1] | ||
| # | ||
| # Cleanup | ||
| # | ||
| connection master; | ||
| drop table t1; | ||
| include/save_master_gtid.inc | ||
| connection slave; | ||
| include/sync_with_master_gtid.inc | ||
| include/rpl_end.inc | ||
| # End of rpl_table_map_metadata_underflow.test |
114 changes: 114 additions & 0 deletions
114
mysql-test/suite/rpl/t/rpl_table_map_metadata_underflow.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # | ||
| # This test verifies that a replica rejects a Table_map event whose field | ||
| # metadata is shorter than the metadata the column types it declares require. | ||
| # The replica must stop the SQL thread with an error rather than decode the | ||
| # metadata past the end of what the event carries, and replication must resume | ||
| # once a well formed copy of the event arrives. | ||
| # | ||
| # MDEV-40646 reported that such an event read past the metadata buffer. A | ||
| # build with AddressSanitizer is the reliable witness of that read, aborting | ||
| # at the first byte past the allocation. A regular debug build does not fault | ||
| # on the read: it decodes adjacent heap and stops the SQL thread with a | ||
| # conversion error whose reported type is rendered from those bytes. This test | ||
| # asserts the rejection the fix adds ahead of the read, which holds on every | ||
| # build. | ||
| # | ||
| # References: | ||
| # * MDEV-40646: Slave Crashes in table_def::table_def() on Malformed | ||
| # Table_map | ||
| # | ||
|
|
||
| --source include/have_debug.inc | ||
| # A Table_map event is only written under row based binary logging. | ||
| --source include/have_binlog_format_row.inc | ||
| --source include/master-slave.inc | ||
|
|
||
| --connection slave | ||
| call mtr.add_suppression("Found invalid event in binary log"); | ||
| call mtr.add_suppression("Relay log read failure: Could not parse relay log event entry"); | ||
|
|
||
| --echo # | ||
| --echo # Initialize test data | ||
| --echo # | ||
|
|
||
| --connection slave | ||
| # Use slave_pos so we can easily reset the relay log after it receives a | ||
| # corrupted event | ||
| --source include/stop_slave.inc | ||
| CHANGE MASTER TO MASTER_USE_GTID=slave_pos; | ||
| --source include/start_slave.inc | ||
|
|
||
| --connection master | ||
| # With 24 columns, the metadata reads run well past the end of the replica's | ||
| # allocation once the event declares a single metadata byte. | ||
| create table t1 (c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int,c17 int,c18 int,c19 int,c20 int,c21 int,c22 int,c23 int,c24 int); | ||
| insert into t1 (c1) values (0); | ||
| --source include/save_master_gtid.inc | ||
|
|
||
| --connection slave | ||
| --source include/sync_with_master_gtid.inc | ||
|
|
||
| --connection master | ||
| set @saved_dbug= @@global.debug_dbug; | ||
|
|
||
| --echo # | ||
| --echo # Test Case: a Table_map declaring more metadata than it carries | ||
| --echo # | ||
|
|
||
| # The reconnect below starts a dump thread that inherits the injection. | ||
| --connection master | ||
| set @@global.debug_dbug= "+d,binlog_sender_undersized_table_map_metadata"; | ||
|
|
||
| --connection slave | ||
| --source include/stop_slave.inc | ||
| --source include/start_slave.inc | ||
|
|
||
| --connection master | ||
| insert into t1 (c1) values (1); | ||
|
|
||
| --connection slave | ||
| --echo # Waiting for the SQL thread to reject the malformed Table_map | ||
| --let $slave_sql_errno= 1594 | ||
| --source include/wait_for_slave_sql_error.inc | ||
|
|
||
| --echo # Ensure the event was rejected before its metadata was decoded | ||
| --let $assert_text= The SQL thread reported an invalid event | ||
| --let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.2.err | ||
| --let $assert_select= Found invalid event in binary log | ||
| --let $assert_count= 1 | ||
| --source include/assert_grep.inc | ||
|
|
||
| --echo # | ||
| --echo # Recover: discard the poisoned relay log and re-fetch a clean copy | ||
| --echo # | ||
| --connection master | ||
| set @@global.debug_dbug= @saved_dbug; | ||
|
|
||
| --connection slave | ||
| --source include/stop_slave_io.inc | ||
| --source include/start_slave.inc | ||
|
|
||
| --echo # | ||
| --echo # Ensure replication works after the invalid event | ||
| --echo # | ||
| --connection master | ||
| insert into t1 (c1) values (2); | ||
| --source include/save_master_gtid.inc | ||
|
|
||
| --connection slave | ||
| --source include/sync_with_master_gtid.inc | ||
| --let $diff_tables=master:t1,slave:t1 | ||
| --source include/diff_tables.inc | ||
|
|
||
| --echo # | ||
| --echo # Cleanup | ||
| --echo # | ||
| --connection master | ||
| drop table t1; | ||
| --source include/save_master_gtid.inc | ||
|
|
||
| --connection slave | ||
| --source include/sync_with_master_gtid.inc | ||
|
|
||
| --source include/rpl_end.inc | ||
| --echo # End of rpl_table_map_metadata_underflow.test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the bug is here, then is actual replication required to reproduce, or is a faulty binlog + SHOW BINLOG EVENTS (or
mariadb-binlog) sufficient?