]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
websocket: limit allocation for small sizes
authorPhilippe Antoine <pantoine@oisf.net>
Mon, 28 Apr 2025 08:11:13 +0000 (10:11 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 28 Apr 2025 18:06:05 +0000 (20:06 +0200)
Fixes: 16f74c68aaa9 ("websocket: use max window bits of 15")
We do not need to allocate 8kbytes for a small message

rust/src/websocket/websocket.rs

index f86101743d4bb1922d5257145cab80535f7be4ed..c1b6bbfa53b8f3edb59f4bb48dbb0ced310c751b 100644 (file)
@@ -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();