From fb40e7b50837d67fe5e8df27995a2c80bdc26296 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 28 Jun 2018 09:48:03 +0200 Subject: [PATCH] Update mtprotoplainsender.py asserts --- telethon/network/mtprotoplainsender.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/telethon/network/mtprotoplainsender.py b/telethon/network/mtprotoplainsender.py index e04e2934..3f789f76 100644 --- a/telethon/network/mtprotoplainsender.py +++ b/telethon/network/mtprotoplainsender.py @@ -39,10 +39,15 @@ class MTProtoPlainSender: raise BrokenAuthKeyError() with BinaryReader(body) as reader: - assert reader.read_long() == 0 # auth_key_id - assert reader.read_long() > msg_id # msg_id - assert reader.read_int() # length + assert reader.read_long() == 0, 'Bad auth_key_id' # auth_key_id + assert reader.read_long() != 0, 'Bad msg_id' # msg_id + # ^ We should make sure that the read ``msg_id`` is greater + # than our own ``msg_id``. However, under some circumstances + # (bad system clock/working behind proxies) this seems to not + # be the case, which would cause endless assertion errors. + + assert reader.read_int() > 0, 'Bad length' # length # We could read length bytes and use those in a new reader to read # the next TLObject without including the padding, but since the # reader isn't used for anything else after this, it's unnecessary.