Skip to content

varbinary column data truncated in RowsEvent #477

Closed
@ckolbitsch-work

Description

@ckolbitsch-work

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions