From 09128d17631906fb3a1b9f3ac480d9cab1febe56 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Mon, 25 Jan 2021 07:06:38 -0800 Subject: [PATCH] use 32kb max hw buffer --- actix-http/src/h1/decoder.rs | 8 +++++++- actix-http/src/h1/dispatcher.rs | 17 +++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index 85379b084..3cf9b3476 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -203,7 +203,13 @@ impl MessageType for Request { (len, method, uri, version, req.headers.len()) } - httparse::Status::Partial => return Ok(None), + httparse::Status::Partial => { + return if src.len() >= super::dispatcher::MAX_HW_BUFFER_SIZE { + Err(ParseError::TooLarge) + } else { + Ok(None) + } + } } }; diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index c90fb14ca..db2393d57 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -31,7 +31,8 @@ use super::payload::{Payload, PayloadSender, PayloadStatus}; use super::{Message, MessageType}; const LW_BUFFER_SIZE: usize = 1024; -const HW_BUFFER_SIZE: usize = 8192; +const HW_BUFFER_SIZE: usize = 1024 * 8; +pub(crate) const MAX_HW_BUFFER_SIZE: usize = HW_BUFFER_SIZE * 4; const MAX_PIPELINED_MESSAGES: usize = 16; bitflags! { @@ -893,13 +894,13 @@ where { let mut read_some = false; - // reserve capacity for buffer - let remaining = buf.capacity() - buf.len(); - if remaining < LW_BUFFER_SIZE { - buf.reserve(HW_BUFFER_SIZE - remaining); - } - loop { + // reserve capacity for buffer + let remaining = buf.capacity() - buf.len(); + if remaining < LW_BUFFER_SIZE { + buf.reserve(HW_BUFFER_SIZE - remaining); + } + match actix_codec::poll_read_buf(Pin::new(io), cx, buf) { Poll::Pending => { return if read_some { Ok(Some(false)) } else { Ok(None) }; @@ -910,7 +911,7 @@ where } else { // If buf is full return but do not disconnect since // there is more reading to be done - if buf.len() >= HW_BUFFER_SIZE { + if buf.len() >= MAX_HW_BUFFER_SIZE { return Ok(Some(false)); }