From fcd5775ae6831e973c580f4a32a0cae9a20f55f6 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Wed, 10 Feb 2021 14:27:47 -0800 Subject: [PATCH] add safety comment --- actix-http/src/ws/mask.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actix-http/src/ws/mask.rs b/actix-http/src/ws/mask.rs index 0d29fa3fc..276ca4a85 100644 --- a/actix-http/src/ws/mask.rs +++ b/actix-http/src/ws/mask.rs @@ -19,6 +19,12 @@ fn apply_mask_fallback(buf: &mut [u8], mask: [u8; 4]) { pub fn apply_mask_fast32(buf: &mut [u8], mask: [u8; 4]) { let mask_u32 = u32::from_ne_bytes(mask); + // SAFETY: + // + // buf is a valid slice borrowed mutably from bytes::BytesMut. + // + // un aligned prefix and suffix would be mask/unmask per byte. + // proper aligned middle slice goes into fast path and operates on 4-byte blocks. let (mut prefix, words, mut suffix) = unsafe { buf.align_to_mut::() }; apply_mask_fallback(&mut prefix, mask); let head = prefix.len() & 3;