Add more checks for HashTable keys.

This commit is contained in:
levlam 2022-07-31 01:15:23 +03:00
parent fc72eeaff7
commit e8b2971a42
4 changed files with 13 additions and 4 deletions

View File

@ -8842,7 +8842,7 @@ void ContactsManager::on_binlog_user_event(BinlogEvent &&event) {
log_event_parse(log_event, event.data_).ensure();
auto user_id = log_event.user_id;
if (have_min_user(user_id)) {
if (have_min_user(user_id) || !user_id.is_valid()) {
LOG(ERROR) << "Skip adding already added " << user_id;
binlog_erase(G()->td_db()->get_binlog(), event.id_);
return;
@ -9150,7 +9150,7 @@ void ContactsManager::on_binlog_chat_event(BinlogEvent &&event) {
log_event_parse(log_event, event.data_).ensure();
auto chat_id = log_event.chat_id;
if (have_chat(chat_id)) {
if (have_chat(chat_id) || !chat_id.is_valid()) {
LOG(ERROR) << "Skip adding already added " << chat_id;
binlog_erase(G()->td_db()->get_binlog(), event.id_);
return;
@ -9388,7 +9388,7 @@ void ContactsManager::on_binlog_channel_event(BinlogEvent &&event) {
log_event_parse(log_event, event.data_).ensure();
auto channel_id = log_event.channel_id;
if (have_channel(channel_id)) {
if (have_channel(channel_id) || !channel_id.is_valid()) {
LOG(ERROR) << "Skip adding already added " << channel_id;
binlog_erase(G()->td_db()->get_binlog(), event.id_);
return;
@ -9642,7 +9642,7 @@ void ContactsManager::on_binlog_secret_chat_event(BinlogEvent &&event) {
log_event_parse(log_event, event.data_).ensure();
auto secret_chat_id = log_event.secret_chat_id;
if (have_secret_chat(secret_chat_id)) {
if (have_secret_chat(secret_chat_id) || !secret_chat_id.is_valid()) {
LOG(ERROR) << "Skip adding already added " << secret_chat_id;
binlog_erase(G()->td_db()->get_binlog(), event.id_);
return;

View File

@ -13875,6 +13875,12 @@ void MessagesManager::on_get_secret_message(SecretChatId secret_chat_id, UserId
CHECK(message_id.is_valid());
CHECK(date > 0);
if (message->random_id_ == 0) {
LOG(ERROR) << "Ignore secret message with random_id == 0";
promise.set_error(Status::Error(400, "Invalid random_id"));
return;
}
auto pending_secret_message = make_unique<PendingSecretMessage>();
pending_secret_message->success_promise = std::move(promise);
MessageInfo &message_info = pending_secret_message->message_info;

View File

@ -5140,6 +5140,7 @@ void StickersManager::get_all_animated_emojis(bool is_recursive,
}
void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise<Unit> &&promise) {
CHECK(custom_emoji_id != 0);
auto &queries = custom_emoji_load_queries_[custom_emoji_id];
queries.push_back(std::move(promise));
if (queries.size() == 1) {
@ -5221,6 +5222,7 @@ void StickersManager::get_custom_emoji_stickers(vector<int64> &&document_ids, bo
}
td::unique(document_ids);
td::remove(document_ids, 0);
vector<int64> unknown_document_ids;
for (auto document_id : document_ids) {

View File

@ -328,6 +328,7 @@ void VoiceNotesManager::on_voice_note_transcribed(FileId file_id, string &&text,
CHECK(voice_note != nullptr);
CHECK(!voice_note->is_transcribed);
CHECK(voice_note->transcription_id == 0 || voice_note->transcription_id == transcription_id);
CHECK(transcription_id != 0);
bool is_changed = voice_note->is_transcribed != is_final || voice_note->text != text;
voice_note->transcription_id = transcription_id;
voice_note->is_transcribed = is_final;