Skip to content

Commit f4498f5

Browse files
committed
Fixes #982
1 parent cfc17ba commit f4498f5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/socket/tcp.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ impl<'a> Socket<'a> {
486486
// [...] the above constraints imply that 2 * the max window size must be less
487487
// than 2**31 [...] Thus, the shift count must be limited to 14 (which allows
488488
// windows of 2**30 = 1 Gbyte).
489+
#[cfg(not(target_pointer_width = "16"))] // Prevent overflow
489490
if rx_capacity > (1 << 30) {
490491
panic!("receiving buffer too large, cannot exceed 1 GiB")
491492
}
@@ -592,10 +593,7 @@ impl<'a> Socket<'a> {
592593
///
593594
#[inline]
594595
fn scaled_window(&self) -> u16 {
595-
cmp::min(
596-
self.rx_buffer.window() >> self.remote_win_shift as usize,
597-
(1 << 16) - 1,
598-
) as u16
596+
u16::try_from(self.rx_buffer.window() >> self.remote_win_shift as usize).unwrap_or(u16::MAX)
599597
}
600598

601599
/// Set the timeout duration.
@@ -1868,7 +1866,10 @@ impl<'a> Socket<'a> {
18681866
let assembler_was_empty = self.assembler.is_empty();
18691867

18701868
// Try adding payload octets to the assembler.
1871-
let Ok(contig_len) = self.assembler.add_then_remove_front(payload_offset, payload_len) else {
1869+
let Ok(contig_len) = self
1870+
.assembler
1871+
.add_then_remove_front(payload_offset, payload_len)
1872+
else {
18721873
net_debug!(
18731874
"assembler: too many holes to add {} octets at offset {}",
18741875
payload_len,
@@ -2155,7 +2156,7 @@ impl<'a> Socket<'a> {
21552156
State::SynSent | State::SynReceived => {
21562157
repr.control = TcpControl::Syn;
21572158
// window len must NOT be scaled in SYNs.
2158-
repr.window_len = self.rx_buffer.window().min((1 << 16) - 1) as u16;
2159+
repr.window_len = u16::try_from(self.rx_buffer.window()).unwrap_or(u16::MAX);
21592160
if self.state == State::SynSent {
21602161
repr.ack_number = None;
21612162
repr.window_scale = Some(self.remote_win_shift);

0 commit comments

Comments
 (0)