Fail HTTP request reading if unexpected end of data reached.

This commit is contained in:
levlam 2023-11-25 02:34:37 +03:00
parent 0d363724e5
commit 511483e12c
3 changed files with 14 additions and 0 deletions

View File

@ -43,6 +43,16 @@ Result<size_t> HttpReader::read_next(HttpQuery *query, bool can_be_slow) {
CHECK(query_ == nullptr);
query_ = query;
}
auto r_size = do_read_next(can_be_slow);
if (state_ != State::ReadHeaders && flow_sink_.is_ready() && r_size.is_ok() && r_size.ok() > 0) {
CHECK(flow_sink_.status().is_ok());
return Status::Error(400, "Bad Request: unexpected end of request content");
}
return r_size;
}
Result<size_t> HttpReader::do_read_next(bool can_be_slow) {
size_t need_size = input_->size() + 1;
while (true) {
if (state_ != State::ReadHeaders) {

View File

@ -87,6 +87,8 @@ class HttpReader {
string temp_file_name_;
int64 file_size_ = 0;
Result<size_t> do_read_next(bool can_be_slow);
Result<size_t> split_header() TD_WARN_UNUSED_RESULT;
void process_header(MutableSlice header_name, MutableSlice header_value);
Result<bool> parse_multipart_form_data(bool can_be_slow) TD_WARN_UNUSED_RESULT;

View File

@ -25,6 +25,7 @@ class ByteFlowInterface {
virtual size_t get_write_size() = 0;
virtual void reset_need_size() {
}
ByteFlowInterface() = default;
ByteFlowInterface(const ByteFlowInterface &) = delete;
ByteFlowInterface &operator=(const ByteFlowInterface &) = delete;
@ -139,6 +140,7 @@ class ByteFlowBaseCommon : public ByteFlowInterface {
bool can_read{true};
bool can_write{true};
Options options_;
void finish(Status status) {
stop_flag_ = true;
need_size_ = 0;