diff --git a/tdnet/td/net/HttpReader.cpp b/tdnet/td/net/HttpReader.cpp index 401425499..f1fa19446 100644 --- a/tdnet/td/net/HttpReader.cpp +++ b/tdnet/td/net/HttpReader.cpp @@ -111,7 +111,7 @@ Result HttpReader::read_next(HttpQuery *query) { gzip_flow_ = GzipByteFlow(Gzip::Mode::Decode); GzipByteFlow::Options options; options.write_watermark.low = 0; - options.write_watermark.high = max_post_size_; + options.write_watermark.high = max(max_post_size_, static_cast(1 << 16)); gzip_flow_.set_options(options); gzip_flow_.set_max_output_size(MAX_CONTENT_SIZE); *source >> gzip_flow_; diff --git a/tdutils/td/utils/ByteFlow.h b/tdutils/td/utils/ByteFlow.h index 04bcf2184..3941a1daa 100644 --- a/tdutils/td/utils/ByteFlow.h +++ b/tdutils/td/utils/ByteFlow.h @@ -379,4 +379,5 @@ class ByteFlowMoveSink : public ByteFlowInterface { ChainBufferReader *input_ = nullptr; ChainBufferWriter *output_ = nullptr; }; + } // namespace td diff --git a/tdutils/test/gzip.cpp b/tdutils/test/gzip.cpp index dd22af2fe..c52cce46b 100644 --- a/tdutils/test/gzip.cpp +++ b/tdutils/test/gzip.cpp @@ -126,7 +126,7 @@ TEST(Gzip, encode_decode_flow_big) { td::clear_thread_locals(); auto start_mem = td::BufferAllocator::get_buffer_mem(); { - auto str = std::string(1000000, 'a'); + auto str = std::string(200000, 'a'); td::ChainBufferWriter input_writer; auto input = input_writer.extract_reader(); td::ByteFlowSource source(&input); @@ -179,7 +179,7 @@ TEST(Gzip, decode_encode_flow_bomb) { td::ByteFlowSink sink; source >> gzip_flow >> sink; - std::string s(1 << 20, 'a'); + std::string s(1 << 16, 'a'); for (size_t i = 0; i < N; i++) { input_writer.append(s); source.wakeup(); @@ -218,7 +218,7 @@ TEST(Gzip, decode_encode_flow_bomb) { sink; ASSERT_TRUE(!sink.is_ready()); - size_t left_size = N * (1 << 20); + size_t left_size = N * (1 << 16); auto validate = [&](td::Slice chunk) { CHECK(chunk.size() <= left_size); left_size -= chunk.size(); @@ -234,8 +234,8 @@ TEST(Gzip, decode_encode_flow_bomb) { gzip_decode_flow.wakeup(); source.wakeup(); auto extra_mem = td::BufferAllocator::get_buffer_mem() - start_mem; - // limit means nothing. just check that we do not use 200Mb or so - CHECK(extra_mem < (10 << 20)); + // limit means nothing. just check that we do not use 15Mb or so + CHECK(extra_mem < (5 << 20)); auto size = sink.get_output()->size(); validate(sink.get_output()->cut_head(size).move_as_buffer_slice().as_slice()); } while (!sink.is_ready()); diff --git a/test/http.cpp b/test/http.cpp index bdcae2265..55476e02d 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -383,8 +383,8 @@ TEST(Http, gzip_bomb_with_limit) { ByteFlowSink sink; source >> gzip_flow >> sink; - std::string s(1 << 20, 'a'); - for (int i = 0; i < 2000; i++) { + std::string s(1 << 16, 'a'); + for (int i = 0; i < 1000; i++) { input_writer.append(s); source.wakeup(); } @@ -411,7 +411,6 @@ TEST(Http, gzip_bomb_with_limit) { LOG(FATAL) << r_state.error(); return; } else if (r_state.ok() == 0) { - LOG(ERROR) << q; ok = true; } }