Description
MySQL columns BINARY and VARBINARY do not seem to have their own type in replication events and are simply streamed as MYSQL_TYPE_STRING or MYSQL_TYPE_VARSTRING, respectively - or, at least, the documentation (see Table 14.4 Column Types) does not list a specific type:
https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::MYSQL_TYPE_STRING
In the parsing of row events, we use the hack module to convert the raw []byte to string instances:
https://github.com/siddontang/go-mysql/blob/master/replication/row_event.go#L541
n = int(length) + 1
v = hack.String(data[1:n])
which seems to strip trailing 0-bytes from the parsed events. For strings, this makes sense, but for binary blobs, it does not.
While the decodeString method returns the extracted length field, the caller in decodeRows only uses this information to advance the position in the buffer:
https://github.com/siddontang/go-mysql/blob/master/replication/row_event.go#L349
row[i], n, err = e.decodeValue(data[pos:], table.ColumnType[i], table.ColumnMeta[i])
if err != nil {
return 0, err
}
pos += n
}
e.Rows = append(e.Rows, row)
return pos, nil
As a result, a client receiving parsed binlog data has no way of know a binary string was truncated due to a 0-byte or not.