From: Philippe Antoine Date: Mon, 28 Apr 2025 08:11:13 +0000 (+0200) Subject: websocket: limit allocation for small sizes X-Git-Tag: suricata-8.0.0-rc1~409 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6436a5cebed11ee3d36a73c4f96c0a2814706375;p=thirdparty%2Fsuricata.git websocket: limit allocation for small sizes Fixes: 16f74c68aaa9 ("websocket: use max window bits of 15") We do not need to allocate 8kbytes for a small message --- diff --git a/rust/src/websocket/websocket.rs b/rust/src/websocket/websocket.rs index f86101743d..c1b6bbfa53 100644 --- a/rust/src/websocket/websocket.rs +++ b/rust/src/websocket/websocket.rs @@ -239,7 +239,12 @@ impl WebSocketState { buf.compress = false; // cf RFC 7692 section-7.2.2 tx.pdu.payload.extend_from_slice(&[0, 0, 0xFF, 0xFF]); - let mut v = Vec::with_capacity(WEBSOCKET_DECOMPRESS_BUF_SIZE); + let mut v = Vec::with_capacity(std::cmp::min( + WEBSOCKET_DECOMPRESS_BUF_SIZE, + // Do not allocate 8kbytes for a small size. + // Numbers here may be optimized. + 256 + 16 * tx.pdu.payload.len(), + )); if let Some(dec) = dec { let expect = dec.total_in() + tx.pdu.payload.len() as u64; let start = dec.total_in();