From 96979d91b6882091b884a071e317fb7986634057 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 5 May 2023 15:37:50 +0300 Subject: [PATCH] Check parameters first in MessagesManager::get_dialog_history. --- td/telegram/MessagesManager.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 6605f1e68..6a7da3d99 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -20979,21 +20979,6 @@ tl_object_ptr MessagesManager::get_dialog_history(DialogId dia promise.set_error(Status::Error(400, "Parameter offset must be greater than or equal to -limit")); return nullptr; } - bool is_limit_increased = false; - if (limit == -offset) { - limit++; - is_limit_increased = true; - } - CHECK(0 < limit && limit <= MAX_GET_HISTORY); - CHECK(-limit < offset && offset <= 0); - - if (from_message_id == MessageId() || from_message_id.get() > MessageId::max().get()) { - from_message_id = MessageId::max(); - } - if (!from_message_id.is_valid()) { - promise.set_error(Status::Error(400, "Invalid value of parameter from_message_id specified")); - return nullptr; - } const Dialog *d = get_dialog_force(dialog_id, "get_dialog_history"); if (d == nullptr) { @@ -21005,13 +20990,25 @@ tl_object_ptr MessagesManager::get_dialog_history(DialogId dia return nullptr; } + if (from_message_id == MessageId() || from_message_id.get() > MessageId::max().get()) { + from_message_id = MessageId::max(); + } + if (!from_message_id.is_valid()) { + promise.set_error(Status::Error(400, "Invalid value of parameter from_message_id specified")); + return nullptr; + } + LOG(INFO) << "Get " << (only_local ? "local " : "") << "history in " << dialog_id << " from " << from_message_id << " with offset " << offset << " and limit " << limit << ", " << left_tries - << " tries left. Last read inbox message is " << d->last_read_inbox_message_id - << ", last read outbox message is " << d->last_read_outbox_message_id - << ", have_full_history = " << d->have_full_history + << " tries left, have_full_history = " << d->have_full_history << ", have_full_history_source = " << d->have_full_history_source; + bool is_limit_increased = false; + if (limit == -offset) { + limit++; + is_limit_increased = true; + } + auto p = d->ordered_messages.get_const_iterator(from_message_id); LOG(DEBUG) << "Iterator points to " << (*p ? (*p)->get_message_id() : MessageId()); bool from_the_end = (d->last_message_id != MessageId() && from_message_id > d->last_message_id) ||