Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid TPKT size was detected #22

Open
HsuJv opened this issue Oct 24, 2022 · 1 comment
Open

Invalid TPKT size was detected #22

HsuJv opened this issue Oct 24, 2022 · 1 comment

Comments

@HsuJv
Copy link

HsuJv commented Oct 24, 2022

Hi @citronneur ,

Thanks for your amazing work to bringing us this crate.
I'm trying to build a wasm application based on your work.
But got some unexpected error "Invalid minimal size for TPKT"
I tried to ignore it and it seems can restore itself.
But when looking through your mstsc-rs code, it seems the program shall be terminated when the error occurs

rdp-rs/src/bin/mstsc-rs.rs

Lines 325 to 344 in 7ac880d

while wait_for_fd(handle as usize) && sync.load(Ordering::Relaxed) {
let mut guard = rdp_client.lock().unwrap();
if let Err(Error::RdpError(e)) = guard.read(|event| {
match event {
RdpEvent::Bitmap(bitmap) => {
bitmap_channel.send(bitmap).unwrap();
},
_ => println!("{}: ignore event", APPLICATION_NAME)
}
}) {
match e.kind() {
RdpErrorKind::Disconnect => {
println!("{}: Server ask for disconnect", APPLICATION_NAME);
},
_ => println!("{}: {:?}", APPLICATION_NAME, e)
}
break;
}
}
}))

See the screenshot which shows it continues to work when the error shows up.
Worked but lots of error

Do you have any idea about this error? 'cuz I cannot observe it when using the mstsc-rs which makes me confused.

BTW, the errors happens at line 142 #1, 159 #2, 166 #3 with the tuple (action, length) shown in the screenshot

rdp-rs/src/core/tpkt.rs

Lines 124 to 172 in 7ac880d

pub fn read(&mut self) -> RdpResult<Payload> {
let mut buffer = Cursor::new(self.transport.read(2)?);
let mut action: u8 = 0;
action.read(&mut buffer)?;
if action == Action::FastPathActionX224 as u8 {
// read padding
let mut padding: u8 = 0;
padding.read(&mut buffer)?;
// now wait extended header
buffer = Cursor::new(self.transport.read(2)?);
let mut size = U16::BE(0);
size.read(&mut buffer)?;
// Minimal size must be 7
// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/18a27ef9-6f9a-4501-b000-94b1fe3c2c10
if size.inner() < 4 {
Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Invalid minimal size for TPKT")))
}
else {
// now wait for body
Ok(Payload::Raw(Cursor::new(self.transport.read(size.inner() as usize - 4)?)))
}
} else {
// fast path
let sec_flag = (action >> 6) & 0x3;
let mut short_length: u8 = 0;
short_length.read(&mut buffer)?;
if short_length & 0x80 != 0 {
let mut hi_length: u8 = 0;
hi_length.read(&mut Cursor::new(self.transport.read(1)?))?;
let length: u16 = ((short_length & !0x80) as u16) << 8;
let length = length | hi_length as u16;
if length < 3 {
Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Invalid minimal size for TPKT")))
} else {
Ok(Payload::FastPath(sec_flag, Cursor::new(self.transport.read(length as usize - 3)?)))
}
}
else {
if short_length < 2 {
Err(Error::RdpError(RdpError::new(RdpErrorKind::InvalidSize, "Invalid minimal size for TPKT")))
} else {
Ok(Payload::FastPath(sec_flag, Cursor::new(self.transport.read(short_length as usize - 2)?)))
}
}
}
}

Thanks in advance

@HsuJv
Copy link
Author

HsuJv commented Oct 25, 2022

Just for your information
I tried to propagate the warning from the library itself to the web console and got the following result
error more
It seems that the tpkt error is not predictive and has nothing to do with the previous warning.

App build from https://github.com/HsuJv/webgateway/tree/main/webrdp if you want to review the client-side code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant