From e4b3f7945803747e70ccfc4bbd2b1dc6e1c93a0f Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 31 Mar 2019 17:05:02 -0700 Subject: [PATCH] allocate enough space --- actix-http/src/ws/frame.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index d4c15627..652746b8 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -172,13 +172,14 @@ impl Parser { }; if payload_len < 126 { + dst.reserve(p_len + 2 + if mask { 4 } else { 0 }); dst.put_slice(&[one, two | payload_len as u8]); } else if payload_len <= 65_535 { - dst.reserve(p_len + 4); + dst.reserve(p_len + 4 + if mask { 4 } else { 0 }); dst.put_slice(&[one, two | 126]); dst.put_u16_be(payload_len as u16); } else { - dst.reserve(p_len + 10); + dst.reserve(p_len + 10 + if mask { 4 } else { 0 }); dst.put_slice(&[one, two | 127]); dst.put_u64_be(payload_len as u64); }; @@ -186,7 +187,7 @@ impl Parser { if mask { let mask = rand::random::(); dst.put_u32_le(mask); - dst.extend_from_slice(payload.as_ref()); + dst.put_slice(payload.as_ref()); let pos = dst.len() - payload_len; apply_mask(&mut dst[pos..], mask); } else {