diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4caf11..56824272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Version 92: * Fix typo in test/CMakeLists.txt * basic_fields::value_type is not copyable * Update repository links in source comments +* Ignore Content-Length in some cases -------------------------------------------------------------------------------- diff --git a/include/boost/beast/http/impl/basic_parser.ipp b/include/boost/beast/http/impl/basic_parser.ipp index f9d1f7da..ee64b6b0 100644 --- a/include/boost/beast/http/impl/basic_parser.ipp +++ b/include/boost/beast/http/impl/basic_parser.ipp @@ -532,6 +532,11 @@ finish_header(error_code& ec, std::true_type) } else if(f_ & flagContentLength) { + if(len_ > body_limit_) + { + ec = error::body_limit; + return; + } if(len_ > 0) { f_ |= flagHasBody; @@ -578,12 +583,20 @@ finish_header(error_code& ec, std::false_type) status_ == 204 || // No Content status_ == 304) // Not Modified { + // VFALCO Content-Length may be present, but we + // treat the message as not having a body. + // https://github.com/boostorg/beast/issues/692 state_ = state::complete; return; } if(f_ & flagContentLength) { + if(len_ > body_limit_) + { + ec = error::body_limit; + return; + } if(len_ > 0) { f_ |= flagHasBody; @@ -876,12 +889,6 @@ do_field(field f, return; } - if(v > body_limit_) - { - ec = error::body_limit; - return; - } - ec.assign(0, ec.category()); len_ = v; f_ |= flagContentLength; diff --git a/test/beast/http/basic_parser.cpp b/test/beast/http/basic_parser.cpp index 0076d958..8d631368 100644 --- a/test/beast/http/basic_parser.cpp +++ b/test/beast/http/basic_parser.cpp @@ -1106,6 +1106,24 @@ public: }); } + // https://github.com/boostorg/beast/issues/692 + void + testIssue692() + { + error_code ec; + test_parser p; + p.eager(true); + string_view s = + "HTTP/1.1 101 Switching Protocols\r\n" + "Content-Length: 2147483648\r\n" + "\r\n"; + p.put(boost::asio::buffer( + s.data(), s.size()), ec); + if(! BEAST_EXPECTS(! ec, ec.message())) + return; + BEAST_EXPECT(p.is_done()); + } + //-------------------------------------------------------------------------- void @@ -1216,6 +1234,7 @@ public: testIssue430(); testIssue452(); testIssue496(); + testIssue692(); testFuzz(); testRegression1(); }