Skip to content

Commit 0db8b00

Browse files
[Pick][0.6 to 0.7] fix(http): fix chunked transfer encoding (alibaba#1115) (alibaba#1116) (alibaba#1117) (alibaba#1119)
* fix(http): Fix stale buffer data being parsed in chunked transfer encoding * fix(http): prevent duplicate stream read in chunked body when parsing final chunk --------- Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com> Co-authored-by: Chen Chen <91253032+yuchen0cc@users.noreply.github.com>
1 parent 13c93b6 commit 0db8b00

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

net/http/body.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ class ChunkedBodyReadStream : public BodyReadStream {
128128
// Quote from rfc2616#section-3.6.1: The chunk-size field is a string of hex digits
129129
// indicating the size of the chunk.
130130
m_chunked_remain = line.substr(0, p).hex_to_uint64();
131+
m_cursor += p + 2;
131132
if (m_chunked_remain != 0 || p == 0) {
132-
m_cursor += p + 2;
133133
return true;
134134
}
135135
m_finish = true;
@@ -190,6 +190,8 @@ class ChunkedBodyReadStream : public BodyReadStream {
190190
m_line_size -= m_cursor;
191191
m_cursor = 0;
192192
}
193+
} else if (m_cursor == m_line_size) { // reset
194+
m_cursor = m_line_size = 0;
193195
}
194196

195197
bool get_line_finish = false;

0 commit comments

Comments
 (0)