Skip to content

Commit 9a64ca2

Browse files
committed
Fixes #982
1 parent cfc17ba commit 9a64ca2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/socket/tcp.rs

Lines changed: 7 additions & 3 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
}
@@ -594,7 +595,7 @@ impl<'a> Socket<'a> {
594595
fn scaled_window(&self) -> u16 {
595596
cmp::min(
596597
self.rx_buffer.window() >> self.remote_win_shift as usize,
597-
(1 << 16) - 1,
598+
u16::MAX as usize,
598599
) as u16
599600
}
600601

@@ -1868,7 +1869,10 @@ impl<'a> Socket<'a> {
18681869
let assembler_was_empty = self.assembler.is_empty();
18691870

18701871
// Try adding payload octets to the assembler.
1871-
let Ok(contig_len) = self.assembler.add_then_remove_front(payload_offset, payload_len) else {
1872+
let Ok(contig_len) = self
1873+
.assembler
1874+
.add_then_remove_front(payload_offset, payload_len)
1875+
else {
18721876
net_debug!(
18731877
"assembler: too many holes to add {} octets at offset {}",
18741878
payload_len,
@@ -2155,7 +2159,7 @@ impl<'a> Socket<'a> {
21552159
State::SynSent | State::SynReceived => {
21562160
repr.control = TcpControl::Syn;
21572161
// window len must NOT be scaled in SYNs.
2158-
repr.window_len = self.rx_buffer.window().min((1 << 16) - 1) as u16;
2162+
repr.window_len = u16::try_from(self.rx_buffer.window()).unwrap_or(u16::MAX);
21592163
if self.state == State::SynSent {
21602164
repr.ack_number = None;
21612165
repr.window_scale = Some(self.remote_win_shift);

0 commit comments

Comments
 (0)