Add notification sound size and duration checks.

This commit is contained in:
levlam 2022-04-18 19:08:32 +03:00
parent a506382e4b
commit a91bed2996
3 changed files with 25 additions and 3 deletions

View File

@ -25,7 +25,9 @@ AudiosManager::AudiosManager(Td *td) : td_(td) {
int32 AudiosManager::get_audio_duration(FileId file_id) const {
auto it = audios_.find(file_id);
CHECK(it != audios_.end());
if (it == audios_.end()) {
return 0;
}
return it->second->duration;
}

View File

@ -29,6 +29,7 @@
#include "td/telegram/TdDb.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UpdatesManager.h"
#include "td/telegram/VoiceNotesManager.h"
#include "td/db/binlog/BinlogEvent.h"
#include "td/db/binlog/BinlogHelper.h"
@ -869,6 +870,24 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
FileId file_id = r_file_id.ok();
auto file_view = td_->file_manager_->get_file_view(file_id);
CHECK(!file_view.empty());
if (file_view.size() > G()->shared_config().get_option_integer("notification_sound_size_max")) {
return promise.set_error(Status::Error(400, "Notification sound file is too big"));
}
auto file_type = file_view.get_type();
int32 duration = 0;
switch (file_type) {
case FileType::Audio:
duration = td_->audios_manager_->get_audio_duration(file_id);
break;
case FileType::VoiceNote:
duration = td_->voice_notes_manager_->get_voice_note_duration(file_id);
break;
default:
break;
}
if (duration > G()->shared_config().get_option_integer("notification_sound_duration_max")) {
return promise.set_error(Status::Error(400, "Notification sound is too long"));
}
if (file_view.has_remote_location() && !file_view.is_encrypted()) {
CHECK(file_view.remote_location().is_document());
if (file_view.main_remote_location().is_web()) {
@ -876,7 +895,6 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
}
FileId ringtone_file_id = file_view.file_id();
auto file_type = file_view.get_type();
if (file_type != FileType::Ringtone) {
if (file_type != FileType::Audio && file_type != FileType::VoiceNote) {
return promise.set_error(Status::Error(400, "Unsupported file specified"));

View File

@ -24,7 +24,9 @@ VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) {
int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const {
auto it = voice_notes_.find(file_id);
CHECK(it != voice_notes_.end());
if (it == voice_notes_.end()) {
return 0;
}
return it->second->duration;
}