1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-12-01 02:44:37 +01:00

fix potential bug in payload processing

This commit is contained in:
Nikolay Kim 2018-03-03 09:27:54 -08:00
parent 6acb6dd4e7
commit 83fcdfd91f

View File

@ -402,6 +402,7 @@ impl Reader {
// read payload // read payload
let done = { let done = {
if let Some(ref mut payload) = self.payload { if let Some(ref mut payload) = self.payload {
'buf: loop {
match utils::read_from_io(io, buf) { match utils::read_from_io(io, buf) {
Ok(Async::Ready(0)) => { Ok(Async::Ready(0)) => {
payload.tx.set_error(PayloadError::Incomplete); payload.tx.set_error(PayloadError::Incomplete);
@ -417,27 +418,35 @@ impl Reader {
} }
_ => (), _ => (),
} }
let is_full = buf.remaining_mut() == 0;
loop { loop {
match payload.decoder.decode(buf) { match payload.decoder.decode(buf) {
Ok(Async::Ready(Some(bytes))) => { Ok(Async::Ready(Some(bytes))) => {
payload.tx.feed_data(bytes); payload.tx.feed_data(bytes);
if payload.decoder.is_eof() { if payload.decoder.is_eof() {
payload.tx.feed_eof(); payload.tx.feed_eof();
break true break 'buf true
} }
}, },
Ok(Async::Ready(None)) => { Ok(Async::Ready(None)) => {
payload.tx.feed_eof(); payload.tx.feed_eof();
break true break 'buf true
},
Ok(Async::NotReady) => {
// if buffer is full then
// socket still can contain more data
if is_full {
continue 'buf
}
return Ok(Async::NotReady)
}, },
Ok(Async::NotReady) =>
return Ok(Async::NotReady),
Err(err) => { Err(err) => {
payload.tx.set_error(err.into()); payload.tx.set_error(err.into());
return Err(ReaderError::Payload) return Err(ReaderError::Payload)
} }
} }
} }
}
} else { } else {
false false
} }
@ -470,7 +479,7 @@ impl Reader {
return Ok(Async::Ready(msg)); return Ok(Async::Ready(msg));
}, },
Async::NotReady => { Async::NotReady => {
if buf.capacity() >= MAX_BUFFER_SIZE { if buf.len() >= MAX_BUFFER_SIZE {
error!("MAX_BUFFER_SIZE unprocessed data reached, closing"); error!("MAX_BUFFER_SIZE unprocessed data reached, closing");
return Err(ReaderError::Error(ParseError::TooLarge)); return Err(ReaderError::Error(ParseError::TooLarge));
} }