Unverified Commit 6d38ea58 authored by Kip's avatar Kip Committed by GitHub

Merge pull request #829 from BenjaminBeichler/master

fix chunked transfer decoding
parents c04166ca 88a30838
......@@ -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