diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 75a631a0..7fec27de 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4954,6 +4954,7 @@ void ContactsManager::save_user_to_database(User *u, UserId user_id) { void ContactsManager::save_user_to_database_impl(User *u, UserId user_id, string value) { CHECK(u != nullptr); CHECK(load_user_from_database_queries_.count(user_id) == 0); + CHECK(!u->is_being_saved); u->is_being_saved = true; u->is_saved = true; u->is_status_saved = true; diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 7c23c4c6..8ada08bf 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -403,7 +403,7 @@ class MessagesDbImpl : public MessagesDbSyncInterface { MessageId last_message_id, int32 date) override { int64 left_message_id = first_message_id.get(); int64 right_message_id = last_message_id.get(); - CHECK(left_message_id <= right_message_id); + CHECK(left_message_id <= right_message_id) << first_message_id << " " << last_message_id; TRY_RESULT(first_messages, get_messages_inner(get_messages_stmt_.asc_stmt_, dialog_id.get(), left_message_id - 1, 1)); if (!first_messages.empty()) { @@ -703,7 +703,7 @@ class MessagesDbImpl : public MessagesDbSyncInterface { Result get_messages_impl(GetMessagesStmt &stmt, DialogId dialog_id, MessageId from_message_id, int32 offset, int32 limit) { - CHECK(dialog_id.is_valid()); + CHECK(dialog_id.is_valid()) << dialog_id; CHECK(from_message_id.is_valid()); auto message_id = from_message_id.get(); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 027f4e9e..885df67b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9214,9 +9214,9 @@ void MessagesManager::fix_message_info_dialog_id(MessageInfo &message_info) cons } MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( - tl_object_ptr message_ptr) const { - LOG(DEBUG) << "Receive " << to_string(message_ptr); - CHECK(message_ptr != nullptr); + tl_object_ptr message_ptr, const char *source) const { + LOG(DEBUG) << "Receive from " << source << " " << to_string(message_ptr); + CHECK(message_ptr != nullptr) << source; int32 constructor_id = message_ptr->get_id(); MessageInfo message_info; @@ -9238,7 +9238,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( if (message->flags_ & MESSAGE_FLAG_IS_SENT_VIA_BOT) { message_info.via_bot_user_id = UserId(message->via_bot_id_); if (!message_info.via_bot_user_id.is_valid()) { - LOG(ERROR) << "Receive invalid " << message_info.via_bot_user_id; + LOG(ERROR) << "Receive invalid " << message_info.via_bot_user_id << " from " << source; message_info.via_bot_user_id = UserId(); } } @@ -9445,7 +9445,7 @@ std::pair> MessagesManager::creat FullMessageId MessagesManager::on_get_message(tl_object_ptr message_ptr, bool from_update, bool is_channel_message, bool have_previous, bool have_next, const char *source) { - return on_get_message(parse_telegram_api_message(std::move(message_ptr)), from_update, is_channel_message, + return on_get_message(parse_telegram_api_message(std::move(message_ptr), source), from_update, is_channel_message, have_previous, have_next, source); } @@ -13543,6 +13543,11 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId void MessagesManager::get_history_from_the_end(DialogId dialog_id, bool from_database, bool only_local, Promise &&promise) { + CHECK(dialog_id.is_valid()); + if (!have_input_peer(dialog_id, AccessRights::Read)) { + // can't get history in dialogs without read access + return promise.set_value(Unit()); + } const int32 limit = MAX_GET_HISTORY; if (from_database && G()->parameters().use_message_db) { LOG(INFO) << "Get history from the end of " << dialog_id << " from database"; @@ -13569,6 +13574,7 @@ void MessagesManager::get_history_from_the_end(DialogId dialog_id, bool from_dat void MessagesManager::get_history(DialogId dialog_id, MessageId from_message_id, int32 offset, int32 limit, bool from_database, bool only_local, Promise &&promise) { + CHECK(dialog_id.is_valid()); if (!have_input_peer(dialog_id, AccessRights::Read)) { // can't get history in dialogs without read access return promise.set_value(Unit()); @@ -19690,7 +19696,8 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob } case telegram_api::channelAdminLogEventActionUpdatePinned::ID: { auto action = move_tl_object_as(action_ptr); - auto message = create_message(parse_telegram_api_message(std::move(action->message_)), true); + auto message = create_message( + parse_telegram_api_message(std::move(action->message_), "channelAdminLogEventActionUpdatePinned"), true); if (message.second == nullptr) { return make_tl_object(); } @@ -19698,8 +19705,12 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob } case telegram_api::channelAdminLogEventActionEditMessage::ID: { auto action = move_tl_object_as(action_ptr); - auto old_message = create_message(parse_telegram_api_message(std::move(action->prev_message_)), true); - auto new_message = create_message(parse_telegram_api_message(std::move(action->new_message_)), true); + auto old_message = create_message( + parse_telegram_api_message(std::move(action->prev_message_), "prev channelAdminLogEventActionEditMessage"), + true); + auto new_message = create_message( + parse_telegram_api_message(std::move(action->new_message_), "new channelAdminLogEventActionEditMessage"), + true); if (old_message.second == nullptr || new_message.second == nullptr || old_message.first != new_message.first) { LOG(ERROR) << "Failed to get edited message"; return nullptr; @@ -19710,7 +19721,8 @@ tl_object_ptr MessagesManager::get_chat_event_action_ob } case telegram_api::channelAdminLogEventActionDeleteMessage::ID: { auto action = move_tl_object_as(action_ptr); - auto message = create_message(parse_telegram_api_message(std::move(action->message_)), true); + auto message = create_message( + parse_telegram_api_message(std::move(action->message_), "channelAdminLogEventActionDeleteMessage"), true); if (message.second == nullptr) { LOG(ERROR) << "Failed to get deleted message"; return nullptr; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 70d940b7..5cfadc9c 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1778,7 +1778,7 @@ class MessagesManager : public Actor { void fix_message_info_dialog_id(MessageInfo &message_info) const; - MessageInfo parse_telegram_api_message(tl_object_ptr message_ptr) const; + MessageInfo parse_telegram_api_message(tl_object_ptr message_ptr, const char *source) const; std::pair> create_message(MessageInfo &&message_info, bool is_channel_message); diff --git a/tdutils/td/utils/tl_helpers.h b/tdutils/td/utils/tl_helpers.h index cab035b0..b02b685c 100644 --- a/tdutils/td/utils/tl_helpers.h +++ b/tdutils/td/utils/tl_helpers.h @@ -28,7 +28,7 @@ bit_offset_store++ #define END_STORE_FLAGS() \ - CHECK(bit_offset_store < 32); \ + CHECK(bit_offset_store < 31); \ td::store(flags_store, storer) #define BEGIN_PARSE_FLAGS() \ @@ -40,7 +40,9 @@ flag = ((flags_parse >> bit_offset_parse) & 1) != 0; \ bit_offset_parse++ -#define END_PARSE_FLAGS() CHECK(bit_offset_parse < 32) +#define END_PARSE_FLAGS() \ + CHECK(bit_offset_parse < 31); \ + CHECK((flags_parse & ~((1 << bit_offset_parse) - 1)) == 0) << flags_parse << " " << bit_offset_parse; namespace td { template