From c2028aed4f62a89efb54d4f1327d9ad650ae2ea0 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 29 Jul 2021 23:39:07 +0300 Subject: [PATCH] Add limit on maximum videoNote size. --- td/telegram/ConfigManager.cpp | 5 ++++- td/telegram/MessagesManager.cpp | 2 +- td/telegram/Td.cpp | 2 ++ td/telegram/cli.cpp | 2 +- td/telegram/files/FileManager.cpp | 15 ++++++++++----- td/telegram/files/FileType.cpp | 1 + 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 028033b76..4d767ae38 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -1684,7 +1684,7 @@ void ConfigManager::process_app_config(tl_object_ptr &c for (auto &video_note_setting : video_note_settings) { CHECK(video_note_setting != nullptr); if (video_note_setting->key_ != "diameter" && video_note_setting->key_ != "video_bitrate" && - video_note_setting->key_ != "audio_bitrate") { + video_note_setting->key_ != "audio_bitrate" && video_note_setting->key_ != "max_size") { continue; } if (video_note_setting->value_->get_id() == telegram_api::jsonNumber::ID) { @@ -1700,6 +1700,9 @@ void ConfigManager::process_app_config(tl_object_ptr &c if (video_note_setting->key_ == "audio_bitrate") { G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", setting_value); } + if (video_note_setting->key_ == "max_size") { + G()->shared_config().set_option_integer("video_note_size_max", setting_value); + } } } else { LOG(ERROR) << "Receive unexpected video note setting " << to_string(video_note_setting); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7cb206425..67affdbff 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -35839,7 +35839,7 @@ void MessagesManager::on_get_channel_difference( } if (!is_final) { - LOG_IF(ERROR, timeout > 0) << "Have timeout in not final ChannelDifference in " << dialog_id; + LOG_IF(ERROR, timeout > 0) << "Have timeout in nonfinal ChannelDifference in " << dialog_id; get_channel_difference(dialog_id, d->pts, true, "on_get_channel_difference"); return; } diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b02ecebf4..63619d3f8 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3565,6 +3565,8 @@ bool Td::is_internal_config_option(Slice name) { name == "rating_e_decay" || name == "recent_stickers_limit"; case 's': return name == "saved_animations_limit"; + case 'v': + return name == "video_note_size_max"; case 'w': return name == "webfile_dc_id"; default: diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 995e774d8..4362f251f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3624,7 +3624,7 @@ class CliClient final : public Actor { string video_path; get_args(args, chat_id, video_path); send_message(chat_id, - td_api::make_object(as_input_file(video_path), nullptr, 1, 5)); + td_api::make_object(as_input_file(video_path), nullptr, 10, 5)); } else if (op == "svenue") { string chat_id; string latitude; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 7bfb61cf3..e4cf97325 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -920,6 +920,7 @@ bool FileManager::are_modification_times_equal(int64 old_mtime, int64 new_mtime) Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size, bool skip_file_size_checks) { constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) - 1 /* 200 KB - 1 B */; constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */; + constexpr int64 DEFAULT_VIDEO_NOTE_SIZE_MAX = 12 * (1 << 20) /* 12 MB */; if (location.path_.empty()) { return Status::Error(400, "File must have non-empty path"); @@ -967,13 +968,17 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64 return Status::Error(400, PSLICE() << "File \"" << location.path_ << "\" is too big for a thumbnail " << tag("size", format::as_size(size))); } - if (location.file_type_ == FileType::Photo && size > MAX_PHOTO_SIZE) { - return Status::Error(400, PSLICE() << "File \"" << location.path_ << "\" is too big for a photo " - << tag("size", format::as_size(size))); - } if (size > MAX_FILE_SIZE) { + return Status::Error(400, PSLICE() << "File \"" << location.path_ << "\" of size " << size << " bytes is too big"); + } + if (location.file_type_ == FileType::Photo && size > MAX_PHOTO_SIZE) { return Status::Error( - 400, PSLICE() << "File \"" << location.path_ << "\" is too big " << tag("size", format::as_size(size))); + 400, PSLICE() << "File \"" << location.path_ << "\" of size " << size << " bytes is too big for a photo"); + } + if (location.file_type_ == FileType::VideoNote && + size > G()->shared_config().get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX)) { + return Status::Error( + 400, PSLICE() << "File \"" << location.path_ << "\" of size " << size << " bytes is too big for a video note"); } return Status::OK(); } diff --git a/td/telegram/files/FileType.cpp b/td/telegram/files/FileType.cpp index 2c1bc50d7..24a719843 100644 --- a/td/telegram/files/FileType.cpp +++ b/td/telegram/files/FileType.cpp @@ -182,6 +182,7 @@ bool is_file_big(FileType file_type, int64 expected_size) { case FileType::ProfilePhoto: case FileType::Photo: case FileType::EncryptedThumbnail: + case FileType::VideoNote: return false; default: break;