Skip to content

Read event header fields unsigned and skip the whole v2 rows-event extra data - #164

Open
cyppe wants to merge 3 commits into
krowinski:masterfrom
cyppe:fix/unsigned-header-and-v2-extra-data
Open

cyppe wants to merge 3 commits into
krowinski:masterfrom
cyppe:fix/unsigned-header-and-v2-extra-data

Conversation

@cyppe

@cyppe cyppe commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Two independent read errors in event decoding, one commit each:

  1. Event header fields read signed (Event::createEventInfo()). The timestamp, server id, event size and next-event position are unsigned 32-bit (binlog_event.h). Read signed, a next position past 2 GiB became negative. EventInfo records only positive positions, so BinLogCurrent, the resume position, stopped advancing inside a binlog file that a large transaction grew past 2 GiB. They are read with readUInt32() now. With semi-sync replication enabled, the acknowledgement now also carries the real position past 2 GiB rather than an older one. On 32-bit PHP, readUInt32() still returns negative values above PHP_INT_MAX, as before; this change is for 64-bit PHP.

  2. v2 rows-event extra data skipped as length / 8 bytes (RowEvent::findTableMap()). The length counts its own two bytes (rows_event.cpp reads it, then subtracts 2). For the usual length 2 the old code skipped nothing, which was right by chance. MySQL 8.0.16+ writes the partition id into every rows event of a partitioned table: a typecode plus one or two 2-byte ids, so a length of 5 or 7. Those bytes were left unread. On MySQL 8.4, a two-row INSERT into a PARTITION BY HASH table decoded as wrong rows with no error. The fix skips length - 2 bytes.

Tests:

  • Unit: EventConsumeHeaderTest::testNextPositionPastTwoGibibytesAdvancesTheBinLogPosition consumes one header whose next position is 0x90000000.
  • Integration: BasicTest::testShouldDecodeRowEventsOfAPartitionedTable covers insert, update across partitions, and delete on a hash-partitioned table. It is skipped on MariaDB and on MySQL before 8.0.16, which write no partition info.

Both fail on master and pass with the fix. The full suite passes locally against MySQL 8.4.13, MySQL 5.7.44 and MariaDB 11.4 (PHP 8.4). The PHP 8.2 CI cells fail on master too (PHPUnit 12 needs PHP 8.3, see #159).

This is the fourth of the small decoder fixes, after #161, #162 and #163, and is independent of them. The zero-length socket read that ends a payload of exactly 16 MiB − 1 is handled in #158, so it is not repeated here.

The timestamp, server id, event size and next-event position are
unsigned 32-bit. Read signed, a next position past 2 GiB became negative,
EventInfo ignored it, and BinLogCurrent stopped advancing inside a
binlog file that a large transaction grew past 2 GiB.
The extra data length counts its own two bytes (rows_event.cpp reads
it and subtracts 2), but findTableMap() skipped length / 8 bytes. For
the usual length 2 that skipped nothing, which was right by chance.
MySQL 8.0.16+ writes the partition id into every rows event of a
partitioned table (typecode plus one or two 2-byte ids, length 5 or 7),
which was left unread: a two-row INSERT into a HASH-partitioned table
decoded as garbage rows. Skip length - 2.
@cyppe
cyppe marked this pull request as ready for review November 14, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant