--source include/have_debug.inc --source include/have_debug_sync.inc --source include/not_embedded.inc --echo # --echo # MDEV-41295 / MDEV-41294 --echo # --echo # Corrupts the real on-disk .MAI file for an internal Aria temp --echo # table in the narrow window between create_internal_tmp_table() --echo # succeeding and open_tmp_table() running, using a DEBUG_SYNC --echo # point (see mdev41295_debug_sync.patch) instead of gdb/external --echo # file surgery. This forces a REAL maria_open() failure -- --echo # "Got error 126 Index is corrupted" -- rather than a synthetic --echo # one, and (until MDEV-41294 is fixed) cascades into a SIGSEGV in --echo # ha_maria::drop_table. --echo # --echo # KNOWN STATE: against an UNFIXED server, this test is expected to --echo # crash the server (mysqld dies mid-query) -- that crash IS the --echo # bug this test demonstrates. Once MDEV-41294's fix (guarding the --echo # NULL 'file' dereference in ha_maria::drop_table) is applied, --echo # this test should instead complete with a clean SQL error and no --echo # crash -- re-record the .result file at that point. --echo # --disable_warnings DROP TABLE IF EXISTS t; --enable_warnings CREATE TABLE t ( id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, value1 char(10) DEFAULT NULL, identifier char(32) DEFAULT NULL, user_id int unsigned DEFAULT NULL, created timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', received timestamp(6) NOT NULL DEFAULT current_timestamp(6), need_reply tinyint(1) DEFAULT 0 ) ENGINE=Aria; INSERT INTO t (value1, identifier, user_id, need_reply) VALUES ('abc', NULL, NULL, 1), (NULL, 'xyz', 1, 1), ('def', NULL, NULL, 1), (NULL, 'xyz', 2, 1); --connect (corrupter, localhost, root,,) --connection default SET debug_sync = 'instantiate_tmp_table_before_open SIGNAL parked WAIT_FOR corrupted'; --echo # Send the CTE query asynchronously -- it will park at the sync --echo # point right after the internal Aria temp table is created but --echo # before it's opened. --send WITH cte AS (SELECT created, received, value1, NULL AS user_id, NULL AS identifier FROM t WHERE need_reply = TRUE AND value1 IS NOT NULL UNION SELECT MIN(created), MAX(received), NULL, GROUP_CONCAT(DISTINCT user_id), identifier FROM t WHERE need_reply = TRUE AND identifier IS NOT NULL GROUP BY identifier) SELECT value1, user_id, identifier FROM cte ORDER BY created; --connection corrupter SET debug_sync = 'now WAIT_FOR parked'; --echo # Pull the server's REAL tmpdir (MTR uses a random per-worker path --echo # under /tmp, not MYSQLTEST_VARDIR/tmp) and hand it to the perl --echo # block below via a plain file. Neither --perl nor --write_file --echo # BODIES get mysqltest's own $variable substitution in this --echo # version (confirmed empirically both ways) -- only single-line --echo # --exec command arguments do. So we use --exec with a plain --echo # shell redirect to write the value out, then read it back --echo # inside --perl using the real MYSQLTEST_VARDIR OS environment --echo # variable (which the MTR harness genuinely exports). --let $ARIA_TMPDIR_VALUE= query_get_value(SELECT @@tmpdir AS Value, Value, 1) --exec echo "$ARIA_TMPDIR_VALUE" > $MYSQLTEST_VARDIR/tmp/aria_tmpdir_value.txt --echo # Locate the internal temp table's .MAI file under the server's --echo # real tmpdir and corrupt the single byte at rec_reflength's --echo # offset (base_pos + 102, decoded from the file's own header --echo # rather than hardcoded, so this stays correct if the table --echo # shape changes). --perl open(my $in, '<', "$ENV{MYSQLTEST_VARDIR}/tmp/aria_tmpdir_value.txt") or die "can't read tmpdir handoff file: $!"; my $tmpdir = <$in>; close($in); chomp $tmpdir; opendir(my $dh, $tmpdir) or die "can't open tmpdir $tmpdir: $!"; my ($mai) = grep { /^#sql-temptable-.*\.MAI$/ } readdir($dh); closedir($dh); die "no #sql-temptable .MAI file found in $tmpdir" unless $mai; my $path = "$tmpdir/$mai"; open(my $fh, '+<:raw', $path) or die "can't open $path: $!"; seek($fh, 12, 0) or die "seek failed: $!"; read($fh, my $base_pos_raw, 2) == 2 or die "short read of base_pos"; my $base_pos = unpack("n", $base_pos_raw); # big-endian uint16 my $rec_reflength_offset = $base_pos + 102; seek($fh, $rec_reflength_offset, 0) or die "seek to target failed: $!"; syswrite($fh, "\xFF", 1) == 1 or die "write failed: $!"; close($fh); print "Corrupted rec_reflength byte at offset $rec_reflength_offset in $path\n"; EOF --remove_file $MYSQLTEST_VARDIR/tmp/aria_tmpdir_value.txt --echo # Release the parked connection to run the real (now doomed) --echo # maria_open() against the corrupted file. SET debug_sync = 'now SIGNAL corrupted'; --connection default --error 0,126,1030,2013 --reap --connection corrupter SET debug_sync = 'RESET'; --disconnect corrupter --connection default --disable_warnings DROP TABLE IF EXISTS t; --enable_warnings