From 92dbf79749885fe3802300d9920617e2b5d9d309 Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:06:09 +0200 Subject: [PATCH] Fixes #982 --- src/socket/tcp.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/socket/tcp.rs b/src/socket/tcp.rs index 946d6de88..603ea67a6 100644 --- a/src/socket/tcp.rs +++ b/src/socket/tcp.rs @@ -510,6 +510,7 @@ impl<'a> Socket<'a> { // [...] the above constraints imply that 2 * the max window size must be less // than 2**31 [...] Thus, the shift count must be limited to 14 (which allows // windows of 2**30 = 1 Gbyte). + #[cfg(not(target_pointer_width = "16"))] // Prevent overflow if rx_capacity > (1 << 30) { panic!("receiving buffer too large, cannot exceed 1 GiB") } @@ -676,10 +677,7 @@ impl<'a> Socket<'a> { /// Used in internal calculations as well as packet generation. #[inline] fn scaled_window(&self) -> u16 { - cmp::min( - self.rx_buffer.window() >> self.remote_win_shift as usize, - (1 << 16) - 1, - ) as u16 + u16::try_from(self.rx_buffer.window() >> self.remote_win_shift as usize).unwrap_or(u16::MAX) } /// Return the last window field value, including scaling according to RFC 1323. @@ -2334,7 +2332,7 @@ impl<'a> Socket<'a> { State::SynSent | State::SynReceived => { repr.control = TcpControl::Syn; // window len must NOT be scaled in SYNs. - repr.window_len = self.rx_buffer.window().min((1 << 16) - 1) as u16; + repr.window_len = u16::try_from(self.rx_buffer.window()).unwrap_or(u16::MAX); if self.state == State::SynSent { repr.ack_number = None; repr.window_scale = Some(self.remote_win_shift);