Remove explicit limit on HTTP chunk size.

This commit is contained in:
levlam 2024-02-29 19:38:57 +03:00
parent 0a3fa80e40
commit 0761329c61
2 changed files with 2 additions and 7 deletions

View File

@ -19,7 +19,7 @@ bool HttpChunkedByteFlow::loop() {
do { do {
if (state_ == State::ReadChunkLength) { if (state_ == State::ReadChunkLength) {
bool ok = find_boundary(input_->clone(), "\r\n", len_); bool ok = find_boundary(input_->clone(), "\r\n", len_);
if (len_ > 10) { if (len_ > 8) {
finish(Status::Error(PSLICE() << "Too long length in chunked " finish(Status::Error(PSLICE() << "Too long length in chunked "
<< input_->cut_head(len_).move_as_buffer_slice().as_slice())); << input_->cut_head(len_).move_as_buffer_slice().as_slice()));
return false; return false;
@ -31,17 +31,13 @@ bool HttpChunkedByteFlow::loop() {
auto s_len = input_->cut_head(len_).move_as_buffer_slice(); auto s_len = input_->cut_head(len_).move_as_buffer_slice();
input_->advance(2); input_->advance(2);
len_ = hex_to_integer<size_t>(s_len.as_slice()); len_ = hex_to_integer<size_t>(s_len.as_slice());
if (len_ > MAX_CHUNK_SIZE) {
finish(Status::Error(PSLICE() << "Invalid chunk size " << tag("size", len_)));
return false;
}
save_len_ = len_; save_len_ = len_;
state_ = State::ReadChunkContent; state_ = State::ReadChunkContent;
} }
auto size = input_->size(); auto size = input_->size();
auto ready = min(len_, size); auto ready = min(len_, size);
auto need_size = min(MIN_UPDATE_SIZE, len_ + 2); auto need_size = min(MIN_UPDATE_SIZE, len_) + 2;
if (size < need_size) { if (size < need_size) {
set_need_size(need_size); set_need_size(need_size);
break; break;

View File

@ -17,7 +17,6 @@ class HttpChunkedByteFlow final : public ByteFlowBase {
bool loop() final; bool loop() final;
private: private:
static constexpr size_t MAX_CHUNK_SIZE = 15 << 20; // some reasonable limit
static constexpr size_t MAX_SIZE = std::numeric_limits<uint32>::max(); // some reasonable limit static constexpr size_t MAX_SIZE = std::numeric_limits<uint32>::max(); // some reasonable limit
static constexpr size_t MIN_UPDATE_SIZE = 1 << 14; static constexpr size_t MIN_UPDATE_SIZE = 1 << 14;
enum class State { ReadChunkLength, ReadChunkContent, OK }; enum class State { ReadChunkLength, ReadChunkContent, OK };