From 0761329c61e4469894bc24337a13b70981e09705 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 29 Feb 2024 19:38:57 +0300 Subject: [PATCH] Remove explicit limit on HTTP chunk size. --- tdnet/td/net/HttpChunkedByteFlow.cpp | 8 ++------ tdnet/td/net/HttpChunkedByteFlow.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/tdnet/td/net/HttpChunkedByteFlow.cpp b/tdnet/td/net/HttpChunkedByteFlow.cpp index cc8e533c3..38510a875 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.cpp +++ b/tdnet/td/net/HttpChunkedByteFlow.cpp @@ -19,7 +19,7 @@ bool HttpChunkedByteFlow::loop() { do { if (state_ == State::ReadChunkLength) { bool ok = find_boundary(input_->clone(), "\r\n", len_); - if (len_ > 10) { + if (len_ > 8) { finish(Status::Error(PSLICE() << "Too long length in chunked " << input_->cut_head(len_).move_as_buffer_slice().as_slice())); return false; @@ -31,17 +31,13 @@ bool HttpChunkedByteFlow::loop() { auto s_len = input_->cut_head(len_).move_as_buffer_slice(); input_->advance(2); len_ = hex_to_integer(s_len.as_slice()); - if (len_ > MAX_CHUNK_SIZE) { - finish(Status::Error(PSLICE() << "Invalid chunk size " << tag("size", len_))); - return false; - } save_len_ = len_; state_ = State::ReadChunkContent; } auto size = input_->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) { set_need_size(need_size); break; diff --git a/tdnet/td/net/HttpChunkedByteFlow.h b/tdnet/td/net/HttpChunkedByteFlow.h index db68ea68f..1f6a3e354 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.h +++ b/tdnet/td/net/HttpChunkedByteFlow.h @@ -17,7 +17,6 @@ class HttpChunkedByteFlow final : public ByteFlowBase { bool loop() final; private: - static constexpr size_t MAX_CHUNK_SIZE = 15 << 20; // some reasonable limit static constexpr size_t MAX_SIZE = std::numeric_limits::max(); // some reasonable limit static constexpr size_t MIN_UPDATE_SIZE = 1 << 14; enum class State { ReadChunkLength, ReadChunkContent, OK };