@@ -486,6 +486,7 @@ impl<'a> Socket<'a> {
486
486
// [...] the above constraints imply that 2 * the max window size must be less
487
487
// than 2**31 [...] Thus, the shift count must be limited to 14 (which allows
488
488
// windows of 2**30 = 1 Gbyte).
489
+ #[ cfg( not( target_pointer_width = "16" ) ) ] // Prevent overflow
489
490
if rx_capacity > ( 1 << 30 ) {
490
491
panic ! ( "receiving buffer too large, cannot exceed 1 GiB" )
491
492
}
@@ -594,7 +595,7 @@ impl<'a> Socket<'a> {
594
595
fn scaled_window ( & self ) -> u16 {
595
596
cmp:: min (
596
597
self . rx_buffer . window ( ) >> self . remote_win_shift as usize ,
597
- ( 1 << 16 ) - 1 ,
598
+ u16 :: MAX as usize ,
598
599
) as u16
599
600
}
600
601
@@ -1868,7 +1869,10 @@ impl<'a> Socket<'a> {
1868
1869
let assembler_was_empty = self . assembler . is_empty ( ) ;
1869
1870
1870
1871
// 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 {
1872
1876
net_debug ! (
1873
1877
"assembler: too many holes to add {} octets at offset {}" ,
1874
1878
payload_len,
@@ -2155,7 +2159,7 @@ impl<'a> Socket<'a> {
2155
2159
State :: SynSent | State :: SynReceived => {
2156
2160
repr. control = TcpControl :: Syn ;
2157
2161
// 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 ) ;
2159
2163
if self . state == State :: SynSent {
2160
2164
repr. ack_number = None ;
2161
2165
repr. window_scale = Some ( self . remote_win_shift ) ;
0 commit comments