diff --git a/crates/ironrdp-blocking/src/connector.rs b/crates/ironrdp-blocking/src/connector.rs index b5951513..9f782335 100644 --- a/crates/ironrdp-blocking/src/connector.rs +++ b/crates/ironrdp-blocking/src/connector.rs @@ -167,7 +167,7 @@ where ); let pdu = framed - .read_by_hint(next_pdu_hint) + .read_by_hint(next_pdu_hint, None) .map_err(|e| ironrdp_connector::custom_err!("read frame by hint", e))?; trace!(length = pdu.len(), "PDU received"); @@ -202,7 +202,7 @@ where ); let pdu = framed - .read_by_hint(next_pdu_hint) + .read_by_hint(next_pdu_hint, None) .map_err(|e| ironrdp_connector::custom_err!("read frame by hint", e))?; trace!(length = pdu.len(), "PDU received"); diff --git a/crates/ironrdp-blocking/src/framed.rs b/crates/ironrdp-blocking/src/framed.rs index c46109bb..bcc2242d 100644 --- a/crates/ironrdp-blocking/src/framed.rs +++ b/crates/ironrdp-blocking/src/framed.rs @@ -87,14 +87,21 @@ where } /// Reads a frame using the provided PduHint. - pub fn read_by_hint(&mut self, hint: &dyn PduHint) -> io::Result { + pub fn read_by_hint(&mut self, hint: &dyn PduHint, mut unmatched: Option<&mut Vec>) -> io::Result { loop { match hint .find_size(self.peek()) .map_err(|e| io::Error::new(io::ErrorKind::Other, e))? { - Some((_matched, length)) => { - return Ok(self.read_exact(length)?.freeze()); + Some((matched, length)) => { + let bytes = self.read_exact(length)?.freeze(); + if matched { + return Ok(bytes); + } else if let Some(ref mut unmatched) = unmatched { + unmatched.push(bytes); + } else { + warn!("Received and lost an unexpected PDU"); + } } None => { let len = self.read()?;