diff options
| author | levlam <levlam@telegram.org> | 2022-08-14 13:30:25 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2022-08-14 13:30:25 +0300 |
| commit | 103c6ad1e8cb1a3a0ab6171073744cfcf17743fe (patch) | |
| tree | a384ef1a905139420a16efb6eb14ad25ec86dd68 /tdnet | |
| parent | 916a5f5848b4726e5debd8986f11dfa9c03371d8 (diff) | |
Increase MAX_CONTENT_SIZE in HttpReader.
Diffstat (limited to 'tdnet')
| -rw-r--r-- | tdnet/td/net/HttpChunkedByteFlow.cpp | 6 | ||||
| -rw-r--r-- | tdnet/td/net/HttpChunkedByteFlow.h | 4 | ||||
| -rw-r--r-- | tdnet/td/net/HttpReader.cpp | 8 | ||||
| -rw-r--r-- | tdnet/td/net/HttpReader.h | 10 |
4 files changed, 16 insertions, 12 deletions
diff --git a/tdnet/td/net/HttpChunkedByteFlow.cpp b/tdnet/td/net/HttpChunkedByteFlow.cpp index 40c213180..95fb850b9 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.cpp +++ b/tdnet/td/net/HttpChunkedByteFlow.cpp @@ -46,12 +46,12 @@ bool HttpChunkedByteFlow::loop() { set_need_size(need_size); break; } - total_size_ += ready; - uncommited_size_ += ready; - if (total_size_ > MAX_SIZE) { + if (total_size_ > MAX_SIZE - ready) { finish(Status::Error(PSLICE() << "Too big query " << tag("size", input_->size()))); return false; } + total_size_ += ready; + uncommited_size_ += ready; output_.append(input_->cut_head(ready)); result = true; diff --git a/tdnet/td/net/HttpChunkedByteFlow.h b/tdnet/td/net/HttpChunkedByteFlow.h index 5b9532769..4e00fb80c 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.h +++ b/tdnet/td/net/HttpChunkedByteFlow.h @@ -17,8 +17,8 @@ class HttpChunkedByteFlow final : public ByteFlowBase { bool loop() final; private: - static constexpr int MAX_CHUNK_SIZE = 15 << 20; // some reasonable limit - static constexpr int MAX_SIZE = std::numeric_limits<int32>::max(); // some reasonable limit + 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 MIN_UPDATE_SIZE = 1 << 14; enum class State { ReadChunkLength, ReadChunkContent, OK }; State state_ = State::ReadChunkLength; diff --git a/tdnet/td/net/HttpReader.cpp b/tdnet/td/net/HttpReader.cpp index 7a914374a..8358debb9 100644 --- a/tdnet/td/net/HttpReader.cpp +++ b/tdnet/td/net/HttpReader.cpp @@ -103,7 +103,7 @@ Result<size_t> HttpReader::read_next(HttpQuery *query, bool can_be_slow) { *source >> flow_sink_; content_ = flow_sink_.get_output(); - if (content_length_ > MAX_CONTENT_SIZE) { + if (content_length_ >= MAX_CONTENT_SIZE) { return Status::Error(413, PSLICE() << "Request Entity Too Large: content length is " << content_length_); } @@ -558,7 +558,11 @@ void HttpReader::process_header(MutableSlice header_name, MutableSlice header_va // TODO: check if protocol is HTTP/1.1 query_->keep_alive_ = true; if (header_name == "content-length") { - content_length_ = to_integer<size_t>(header_value); + auto content_length = to_integer<uint64>(header_value); + if (content_length > MAX_CONTENT_SIZE) { + content_length = MAX_CONTENT_SIZE; + } + content_length_ = static_cast<size_t>(content_length); } else if (header_name == "connection") { to_lower_inplace(header_value); if (header_value == "close") { diff --git a/tdnet/td/net/HttpReader.h b/tdnet/td/net/HttpReader.h index 4e86795a3..3851e7467 100644 --- a/tdnet/td/net/HttpReader.h +++ b/tdnet/td/net/HttpReader.h @@ -101,11 +101,11 @@ class HttpReader { void close_temp_file(); void clean_temporary_file(); - static constexpr size_t MAX_CONTENT_SIZE = std::numeric_limits<int32>::max(); // Some reasonable limit - static constexpr size_t MAX_TOTAL_PARAMETERS_LENGTH = 1 << 20; // Some reasonable limit - static constexpr size_t MAX_TOTAL_HEADERS_LENGTH = 1 << 18; // Some reasonable limit - static constexpr size_t MAX_BOUNDARY_LENGTH = 70; // As defined by RFC1341 - static constexpr int64 MAX_FILE_SIZE = static_cast<int64>(4000) << 20; // Telegram server file size limit + static constexpr size_t MAX_CONTENT_SIZE = std::numeric_limits<uint32>::max(); // Some reasonable limit + static constexpr size_t MAX_TOTAL_PARAMETERS_LENGTH = 1 << 20; // Some reasonable limit + static constexpr size_t MAX_TOTAL_HEADERS_LENGTH = 1 << 18; // Some reasonable limit + static constexpr size_t MAX_BOUNDARY_LENGTH = 70; // As defined by RFC1341 + static constexpr int64 MAX_FILE_SIZE = static_cast<int64>(4000) << 20; // Telegram server file size limit static constexpr const char TEMP_DIRECTORY_PREFIX[] = "tdlib-server-tmp"; }; |
