From feb238c5d9a10f5c31e31534909fb953f5652b9c Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 14 Mar 2019 14:14:24 +0400 Subject: [PATCH] Fix crash if asked to read more than 64MB at once. --- .../media/streaming/media_streaming_file.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp index 8a1663662..daf324522 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_file.cpp @@ -12,6 +12,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Media { namespace Streaming { +namespace { + +constexpr auto kMaxSingleReadAmount = 8 * 1024 * 1024; + +} // namespace File::Context::Context( not_null delegate, @@ -32,7 +37,13 @@ int64_t File::Context::Seek(void *opaque, int64_t offset, int whence) { int File::Context::read(bytes::span buffer) { const auto amount = std::min(size_type(_size - _offset), buffer.size()); - if (unroll() || amount < 0) { + Assert(amount >= 0); + + if (unroll()) { + return -1; + } else if (amount > kMaxSingleReadAmount) { + LOG(("Streaming Error: Read callback asked for too much data: %1" + ).arg(amount)); return -1; } else if (!amount) { return amount;