Skip to content

Commit 21b695b

Browse files
committed
Read TLV length correctly in optional metadata
1 parent 5b87b95 commit 21b695b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/binlog/events/table_map_event.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use std::{borrow::Cow, cmp::min, convert::TryFrom, io, iter::Peekable};
1010

1111
use bitvec::prelude::*;
12-
use byteorder::ReadBytesExt;
12+
use byteorder::{LittleEndian, ReadBytesExt};
1313
use saturating::Saturating as S;
1414

1515
use crate::{
@@ -1159,7 +1159,13 @@ impl<'a> OptionalMetadataIter<'a> {
11591159
/// Reads type-length-value value.
11601160
fn read_tlv(&mut self) -> io::Result<(RawConst<u8, OptionalMetadataFieldType>, &'a [u8])> {
11611161
let t = self.data.read_u8()?;
1162-
let l = self.data.read_u8()? as usize;
1162+
// The length is encoded in 1, 3 or 8 bytes (https://github.com/mysql/mysql-server/blob/824e2b4064053f7daf17d7f3f84b7a3ed92e5fb4/libs/mysql/binlog/event/binlog_event.h#L812)
1163+
let l = match self.data.read_u8()? {
1164+
252 => self.data.read_u16::<LittleEndian>()? as usize,
1165+
253 => self.data.read_u24::<LittleEndian>()? as usize,
1166+
254 => self.data.read_u64::<LittleEndian>()? as usize,
1167+
t => t as usize,
1168+
};
11631169
let v = match self.data.get(..l) {
11641170
Some(v) => v,
11651171
None => {

0 commit comments

Comments
 (0)