1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +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
let done = {
if let Some(ref mut payload) = self.payload {
'buf: loop {
match utils::read_from_io(io, buf) {
Ok(Async::Ready(0)) => {
payload.tx.set_error(PayloadError::Incomplete);
@ -417,27 +418,35 @@ impl Reader {
}
_ => (),
}
let is_full = buf.remaining_mut() == 0;
loop {
match payload.decoder.decode(buf) {
Ok(Async::Ready(Some(bytes))) => {
payload.tx.feed_data(bytes);
if payload.decoder.is_eof() {
payload.tx.feed_eof();
break true
break 'buf true
}
},
Ok(Async::Ready(None)) => {
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) => {
payload.tx.set_error(err.into());
return Err(ReaderError::Payload)
}
}
}
}
} else {
false
}
@ -470,7 +479,7 @@ impl Reader {
return Ok(Async::Ready(msg));
},
Async::NotReady => {
if buf.capacity() >= MAX_BUFFER_SIZE {
if buf.len() >= MAX_BUFFER_SIZE {
error!("MAX_BUFFER_SIZE unprocessed data reached, closing");
return Err(ReaderError::Error(ParseError::TooLarge));
}