Bug #17654 mysqlbinlog: --read-from-remote-server causes core
Submitted: 22 Feb 2006 20:00 Modified: 6 Jun 2007 15:10
Reporter: Jonathan Miller Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:5.1.18-bk OS:Linux (Linux 32 Bit OS)
Assigned to: Chuck Bell CPU Architecture:Any

[22 Feb 2006 20:00] Jonathan Miller
Description:
Found this one by accident:
Command:
 $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000001 >$MYSQLTEST_VARDIR/tmp/remote.sql

What I meant for it to be:
 $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 >$MYSQLTEST_VARDIR/tmp/remote.sql

Core BT:
#0  Log_event::print_base64 (this=0x0, file=0x9d85e0, print_event_info=0xbfcbabec)
    at log_event.cc:1007
1007      my_off_t size= uint4korr(ptr + EVENT_LEN_OFFSET);
(gdb) bt
#0  Log_event::print_base64 (this=0x0, file=0x9d85e0, print_event_info=0xbfcbabec)
    at log_event.cc:1007
#1  0x08055d77 in process_event (print_event_info=0xbfcbabec, ev=0x83ba8a0, pos=565)
    at mysqlbinlog.cc:652
#2  0x0805c459 in main (argc=1, argv=0x83a6060) at mysqlbinlog.cc:1167

MySQL Test Failure:
rpl_row_mysqlbinlog            [ fail ]

Errors are (from /home/ndbdev/jmiller/clones/mysql-5.1-new/mysql-test/var/log/mysqltest-time) :
sh: line 1:  5472 Segmentation fault      (core dumped) $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000001 >$MYSQLTEST_VARDIR/tmp/remote.sql
mysqltest: At line 163: command "$MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 $MYSQLTEST_VARDIR/log/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql" failed
(the last lines may be the most important ones)

How to repeat:
See above
[22 Feb 2006 20:07] Jonathan Miller
Okay, so I was wrong, it cores with a good command line as well:
--exec $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql

TEST                            RESULT
-------------------------------------------------------
rpl_row_mysqlbinlog            [ fail ]

Errors are (from /home/ndbdev/jmiller/clones/mysql-5.1-new/mysql-test/var/log/mysqltest-time) :
sh: line 1:  8877 Segmentation fault      (core dumped) $MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 >$MYSQLTEST_VARDIR/tmp/remote.sql
mysqltest: At line 163: command "$MYSQL_BINLOG --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 > $MYSQLTEST_VARDIR/tmp/remote.sql" failed

#0  Log_event::print_base64 (this=0x0, file=0x9d85e0, print_event_info=0xbf81f12c)
    at log_event.cc:1007
1007      my_off_t size= uint4korr(ptr + EVENT_LEN_OFFSET);
(gdb) bt
#0  Log_event::print_base64 (this=0x0, file=0x9d85e0, print_event_info=0xbf81f12c)
    at log_event.cc:1007
#1  0x08055d77 in process_event (print_event_info=0xbf81f12c, ev=0x8b678a0, pos=565)
    at mysqlbinlog.cc:652
#2  0x0805c459 in main (argc=0, argv=0x8b53060) at mysqlbinlog.cc:1167
[22 Feb 2006 22:15] Jonathan Miller
The code that produced this bug is in the new rpl_row_mysqlbinlog.test case and has been commented out. Once corrected, please uncommint this test code. In addition, a new results file will need to be generated.

Thanks
[30 Oct 2006 8:40] Ingo Strüwing
There seems to be a similar problem on Windows:

rpl_row_mysqlbinlog            [ fail ]

Errors are (from e:/pb/mysql-5.1-engines/65/mysql-5.1.13-beta-pb65/mysql-test/var-ps_row-6/log/mysqltest-time) :
ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 98, event_type: 15
ERROR: Error in Log_event::read_log_event(): 'read error', data_len: 98, event_type: 15
ERROR: Could not read a Format_description_log_event event at offset 4 ; this could be a log format error or read error
mysqltest: At line 266: command "$MYSQL_BINLOG --short-form --position=412 - < $MYSQLTEST_VARDIR/log/master-bin.000001" failed
(the last lines may be the most important ones)
Result from queries before failure can be found in r/rpl_row_mysqlbinlog.log

See https://intranet.mysql.com/~knielsen/pb/getlog.pl?dir=mysql-5.1-engines&entry=istruewing@c...
[2 May 2007 20:01] Serge Kozlov
Confirmed for 5.1.18. Attached file is test case for the bug report.
[2 May 2007 20:01] Serge Kozlov
testcase

Attachment: bug17654.tar.gz (application/x-gzip, text), 624 bytes.

[8 May 2007 19:36] Chuck Bell
The problem is the print_base64() method in log_event.cc expects the log_event::temp_buf member variable to point to the incoming binlog event in the buffer. When running mysqlbinlog reading from a file, the code calls log_event::read_log_event(IO_CACHE* file,const Format_description_log_event *description_event) which correctly sets up the temp_buf member variable. The code then calls Log_event::read_log_event(const char* buf, uint event_len, const char **error, const Format_description_log_event *description_event) which reads the log event.

However, when reading the binlog from a remote host, the code does not call log_event::read_log_event(IO_CACHE* file, const Format_description_log_event *description_event) first, but does call Log_event::read_log_event(const char* buf, uint event_len, const char **error, const Format_description_log_event *description_event), and thus when the code reaches the print_base64() method, the temp_buf member variable is undefined resulting in a crash when it is accessed on line# 1164/1165.

The proposed patch places a call to log_event::register_temp_buf() which takes one parameter (the incoming stream) and assigns it to the temp_buf member variable. This patch is placed in the dump_remote_log_entries() method in mysqlbinlog.cc.
[8 May 2007 19:37] Chuck Bell
The problem is the print_base64() method in log_event.cc expects the log_event::temp_buf member variable to point to the incoming binlog event in the buffer. When running mysqlbinlog reading from a file, the code calls log_event::read_log_event(IO_CACHE* file,const Format_description_log_event *description_event) which correctly sets up the temp_buf member variable. The code then calls Log_event::read_log_event(const char* buf, uint event_len, const char **error, const Format_description_log_event *description_event) which reads the log event.

However, when reading the binlog from a remote host, the code does not call log_event::read_log_event(IO_CACHE* file, const Format_description_log_event *description_event) first, but does call Log_event::read_log_event(const char* buf, uint event_len, const char **error, const Format_description_log_event *description_event), and thus when the code reaches the print_base64() method, the temp_buf member variable is undefined resulting in a crash when it is accessed on line# 1164/1165.

The proposed patch places a call to log_event::register_temp_buf() which takes one parameter (the incoming stream) and assigns it to the temp_buf member variable. This patch is placed in the dump_remote_log_entries() method in mysqlbinlog.cc.
[8 May 2007 20:20] Chuck Bell
Patch committed 8 May. See http://lists.mysql.com/commits/26328 for details. Awaiting review.
[22 May 2007 15:00] Chuck Bell
Patch submitted on 22 May @ 1100 EST.
[30 May 2007 11:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/27674

ChangeSet@1.2526, 2007-05-30 14:29:34+03:00, aelkin@dsl-hkibras1-ff5dc300-70.dhcp.inet.fi +1 -0
  bug#17654  --read-from-remote-server causes core
  
  fixing FD event issue that showed up on pb.
[1 Jun 2007 19:25] Bugs System
Pushed into 5.1.20-beta
[6 Jun 2007 15:10] MC Brown
A note has been added to the 5.1.20 changelog.
[17 Jun 2009 19:22] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090616183122-chjzbaa30qopdra9) (version source revid:alexey.kopytov@sun.com-20090508175345-5yq0ntwtz7d99d1i) (merge vers: 6.0.12-alpha) (pib:11)
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-7.0.8 (revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-6.3.27 (revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (version source revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (merge vers: 5.1.37-ndb-6.3.27) (pib:11)
[26 Aug 2009 13:48] Bugs System
Pushed into 5.1.37-ndb-6.2.19 (revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (version source revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (merge vers: 5.1.37-ndb-6.2.19) (pib:11)
[27 Aug 2009 16:33] Bugs System
Pushed into 5.1.35-ndb-7.1.0 (revid:magnus.blaudd@sun.com-20090827163030-6o3kk6r2oua159hr) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)