Skip to content

Commit

Permalink
Read TLV length correctly in optional metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
maorsaleh committed Jun 6, 2024
1 parent 5b87b95 commit 21b695b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/binlog/events/table_map_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::{borrow::Cow, cmp::min, convert::TryFrom, io, iter::Peekable};

use bitvec::prelude::*;
use byteorder::ReadBytesExt;
use byteorder::{LittleEndian, ReadBytesExt};
use saturating::Saturating as S;

use crate::{
Expand Down Expand Up @@ -1159,7 +1159,13 @@ impl<'a> OptionalMetadataIter<'a> {
/// Reads type-length-value value.
fn read_tlv(&mut self) -> io::Result<(RawConst<u8, OptionalMetadataFieldType>, &'a [u8])> {
let t = self.data.read_u8()?;
let l = self.data.read_u8()? as usize;
// 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)
let l = match self.data.read_u8()? {
252 => self.data.read_u16::<LittleEndian>()? as usize,
253 => self.data.read_u24::<LittleEndian>()? as usize,
254 => self.data.read_u64::<LittleEndian>()? as usize,
t => t as usize,
};
let v = match self.data.get(..l) {
Some(v) => v,
None => {
Expand Down

0 comments on commit 21b695b

Please sign in to comment.