fix(#287): Clamp max websocket message size to 32MB

This commit is contained in:
Σrebe - Romain GERARD 2024-06-07 21:25:05 +02:00
parent 0da43e1643
commit bb266f6899
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4

View file

@ -53,10 +53,12 @@ impl TunnelWrite for WebsocketTunnelWrite {
} }
// If the buffer has been completely filled with previous read, Grows it ! // If the buffer has been completely filled with previous read, Grows it !
// For the buffer to not be a bottleneck when the TCP window scale // For the buffer to not be a bottleneck when the TCP window scale.
// For udp, the buffer will never grows. // We clamp it to 32Mb to avoid unbounded growth and as websocket max frame size is 64Mb by default
// For udp, the buffer will never grow.
const _32_MB: usize = 32 * 1024 * 1024;
buf.clear(); buf.clear();
if buf.capacity() == read_len { if buf.capacity() == read_len && buf.capacity() < _32_MB {
let new_size = buf.capacity() + (buf.capacity() / 4); // grow buffer by 1.25 % let new_size = buf.capacity() + (buf.capacity() / 4); // grow buffer by 1.25 %
buf.reserve(new_size); buf.reserve(new_size);
trace!( trace!(