Skip to content

Commit c8f7c29

Browse files
authored
Fix: Short packets panic over TCP GH-290
Fix: Short packets panic over TCP GH-290
2 parents 4dd9a12 + ad9a0f6 commit c8f7c29

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/player/packet_bus.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ impl PacketBus {
120120
Socket::Web(socket) => match socket.next().await {
121121
Some(Ok(Message::Binary(buf))) => {
122122
if buf.len() < 4 {
123-
return None;
123+
return Some(Err(std::io::Error::new(
124+
std::io::ErrorKind::InvalidData,
125+
format!("Received packet is too short: {}", buf.len()),
126+
)));
124127
}
125128

126129
let mut data_buf = buf[2..].to_vec();
@@ -172,6 +175,16 @@ impl PacketBus {
172175
match read.await {
173176
Some(Ok(buf)) => {
174177
let mut data_buf = buf;
178+
if data_buf.len() < 3 {
179+
return Some(Err(std::io::Error::new(
180+
std::io::ErrorKind::InvalidData,
181+
format!(
182+
"Received packet is too short: {}",
183+
data_buf.len()
184+
),
185+
)));
186+
}
187+
175188
if self.client_enryption_multiple != 0 {
176189
decrypt_packet(
177190
&mut data_buf,

src/player/player_handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ async fn run_player(mut player: Player) {
288288
break;
289289
},
290290
_ => {
291-
player.close(format!("Due to unknown error: {:?}", e)).await;
291+
player.close(format!("{}", e)).await;
292292
break;
293293
}
294294
}

0 commit comments

Comments
 (0)