Skip to content

Commit

Permalink
[update] http_parse / 先頭の0x,0Xを許容し,ある場合用にchunk size文字数の上限を10桁にした
Browse files Browse the repository at this point in the history
  • Loading branch information
habvi committed Oct 12, 2024
1 parent 12c37e6 commit ee341f0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion srcs/http/request/parse/http_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ChunkSizeResult GetChunkSizeStr(const std::string &current_buf) {

const std::string::size_type end_of_chunk_size_pos = current_buf.find(CRLF);
if (end_of_chunk_size_pos == std::string::npos) {
if (current_buf.size() > 8) { // INT_MAX: 7FFFFFFF(8digits)
if (current_buf.size() > 10) { // INT_MAX: 0x7FFFFFFF(10digits)
throw HttpException("Error: incorrect chunk size", StatusCode(BAD_REQUEST));
}
result.Set(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Transfer-Encoding: chunked

4
Wiki
1234567890
12345678901
7 changes: 4 additions & 3 deletions test/webserv/unit/http_parse/test_http_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ int main(void) {
test13_body_message_chunked.request_result.request.body_message = "Wikipedia";
test13_body_message_chunked.current_buf = "80000000\r\naaa";

// 24.Chunked Transfer-Encodingの場合で、\r\nが含まれずchunk_sizeが8桁より多い場合は早期に400
// 24.Chunked Transfer-Encodingの場合で、
// \r\nが含まれずchunk_sizeが10桁(0x7FFFFFFF)より多い場合は早期に400
http::HttpRequestParsedData test14_body_message_chunked;
test14_body_message_chunked.request_result.status_code = http::StatusCode(http::BAD_REQUEST);
test14_body_message_chunked.request_result.request.request_line =
Expand All @@ -638,7 +639,7 @@ int main(void) {
test14_body_message_chunked.is_request_format.is_header_fields = true;
test14_body_message_chunked.is_request_format.is_body_message = false;
test14_body_message_chunked.request_result.request.body_message = "Wikipedia";
test14_body_message_chunked.current_buf = "123456789";
test14_body_message_chunked.current_buf = "12345678901";

static const TestCase test_case_http_request_body_message_format_with_chunked[] = {
TestCase(
Expand Down Expand Up @@ -709,7 +710,7 @@ int main(void) {
),
TestCase(
"POST / HTTP/1.1\r\nHost: host\r\nTransfer-Encoding: chunked\r\nContent-Type: "
"text/plain\r\n\r\n4\r\nWiki\r\n5\r\npedia\r\n123456789",
"text/plain\r\n\r\n4\r\nWiki\r\n5\r\npedia\r\n12345678901",
test14_body_message_chunked
),
};
Expand Down

0 comments on commit ee341f0

Please sign in to comment.