Skip to content

Commit c761429

Browse files
committed
Enforce 8KB sanity limit on chunk headers
1 parent 57f95cb commit c761429

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/boost/beast/http/impl/basic_parser.ipp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,11 @@ parse_chunk_header(char const*& in,
613613
return;
614614
if(! eol)
615615
{
616+
if(n + skip_ >= 8192)
617+
{
618+
BOOST_BEAST_ASSIGN_EC(ec, error::bad_chunk_extension);
619+
return;
620+
}
616621
BOOST_BEAST_ASSIGN_EC(ec, error::need_more);
617622
if(p != pend)
618623
skip_ = pend - p - 1;

test/beast/http/basic_parser.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,22 @@ class basic_parser_test : public beast::unit_test::suite
946946
p.put(b.data(), ec);
947947
BEAST_EXPECTS(ec == error::body_limit, ec.message());
948948
}
949+
{
950+
multi_buffer b;
951+
ostream(b) <<
952+
"POST / HTTP/1.1\r\n"
953+
"Transfer-Encoding: chunked\r\n"
954+
"\r\n"
955+
"1;" << std::string(8192 - 3, 'x');
956+
error_code ec;
957+
test_parser<true> p;
958+
p.eager(true);
959+
b.consume(p.put(b.data(), ec));
960+
BEAST_EXPECTS(ec == error::need_more, ec.message());
961+
ostream(b) << 'x';
962+
b.consume(p.put(b.data(), ec));
963+
BEAST_EXPECTS(ec == error::bad_chunk_extension, ec.message());
964+
}
949965
}
950966

951967
//--------------------------------------------------------------------------

0 commit comments

Comments
 (0)