Add limit on maximum videoNote size.

This commit is contained in:
levlam 2021-07-29 23:39:07 +03:00
parent f0333aa578
commit c2028aed4f
6 changed files with 19 additions and 8 deletions

View File

@ -1684,7 +1684,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
for (auto &video_note_setting : video_note_settings) { for (auto &video_note_setting : video_note_settings) {
CHECK(video_note_setting != nullptr); CHECK(video_note_setting != nullptr);
if (video_note_setting->key_ != "diameter" && video_note_setting->key_ != "video_bitrate" && 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; continue;
} }
if (video_note_setting->value_->get_id() == telegram_api::jsonNumber::ID) { if (video_note_setting->value_->get_id() == telegram_api::jsonNumber::ID) {
@ -1700,6 +1700,9 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
if (video_note_setting->key_ == "audio_bitrate") { if (video_note_setting->key_ == "audio_bitrate") {
G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", setting_value); 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 { } else {
LOG(ERROR) << "Receive unexpected video note setting " << to_string(video_note_setting); LOG(ERROR) << "Receive unexpected video note setting " << to_string(video_note_setting);

View File

@ -35839,7 +35839,7 @@ void MessagesManager::on_get_channel_difference(
} }
if (!is_final) { 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"); get_channel_difference(dialog_id, d->pts, true, "on_get_channel_difference");
return; return;
} }

View File

@ -3565,6 +3565,8 @@ bool Td::is_internal_config_option(Slice name) {
name == "rating_e_decay" || name == "recent_stickers_limit"; name == "rating_e_decay" || name == "recent_stickers_limit";
case 's': case 's':
return name == "saved_animations_limit"; return name == "saved_animations_limit";
case 'v':
return name == "video_note_size_max";
case 'w': case 'w':
return name == "webfile_dc_id"; return name == "webfile_dc_id";
default: default:

View File

@ -3624,7 +3624,7 @@ class CliClient final : public Actor {
string video_path; string video_path;
get_args(args, chat_id, video_path); get_args(args, chat_id, video_path);
send_message(chat_id, send_message(chat_id,
td_api::make_object<td_api::inputMessageVideoNote>(as_input_file(video_path), nullptr, 1, 5)); td_api::make_object<td_api::inputMessageVideoNote>(as_input_file(video_path), nullptr, 10, 5));
} else if (op == "svenue") { } else if (op == "svenue") {
string chat_id; string chat_id;
string latitude; string latitude;

View File

@ -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) { 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_THUMBNAIL_SIZE = 200 * (1 << 10) - 1 /* 200 KB - 1 B */;
constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */; 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()) { if (location.path_.empty()) {
return Status::Error(400, "File must have non-empty path"); 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 " return Status::Error(400, PSLICE() << "File \"" << location.path_ << "\" is too big for a thumbnail "
<< tag("size", format::as_size(size))); << 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) { 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( 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(); return Status::OK();
} }

View File

@ -182,6 +182,7 @@ bool is_file_big(FileType file_type, int64 expected_size) {
case FileType::ProfilePhoto: case FileType::ProfilePhoto:
case FileType::Photo: case FileType::Photo:
case FileType::EncryptedThumbnail: case FileType::EncryptedThumbnail:
case FileType::VideoNote:
return false; return false;
default: default:
break; break;