Commit 88a30838 authored by Benjamin Beichler's avatar Benjamin Beichler Committed by Benjamin Beichler

fix chunked transfer decoding

- usage of complete body_.size() seems is wrong (only valid if there is one chunk?)
- use separate var to count already received bytes of chunk
parent a54a4fab
......@@ -502,6 +502,7 @@ private:
Message *message;
size_t bytesRead;
ssize_t size;
ssize_t alreadyAppendedChunkBytes;
};
State parseContentLength(StreamCursor &cursor,
......
......@@ -412,6 +412,7 @@ BodyStep::Chunk::Result BodyStep::Chunk::parse(StreamCursor &cursor) {
revert.ignore();
size = sz;
alreadyAppendedChunkBytes = 0;
}
if (size == 0)
......@@ -421,17 +422,18 @@ BodyStep::Chunk::Result BodyStep::Chunk::parse(StreamCursor &cursor) {
StreamCursor::Token chunkData(cursor);
const ssize_t available = cursor.remaining();
if (static_cast<ssize_t>(available + message->body_.size()) < size) {
if (available + alreadyAppendedChunkBytes < size + 2) {
cursor.advance(available);
message->body_.append(chunkData.rawText(), available);
alreadyAppendedChunkBytes +=available;
return Incomplete;
}
cursor.advance(size - message->body_.size());
cursor.advance(size - alreadyAppendedChunkBytes);
//trailing EOL
cursor.advance(2);
if (!cursor.advance(2))
return Incomplete;
message->body_.append(chunkData.rawText(), size - message->body_.size());
message->body_.append(chunkData.rawText(), size - alreadyAppendedChunkBytes);
return Complete;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment