Improve unhelpful 'readexactly size can not be less than zero'

Technically closes #4092, as the error is now properly handled.
This commit is contained in:
Lonami Exo 2023-04-29 12:33:32 +02:00
parent 9aad453e1a
commit 03ff996ace

View File

@ -30,6 +30,11 @@ class FullPacketCodec(PacketCodec):
# See https://github.com/LonamiWebs/Telethon/issues/4042. # See https://github.com/LonamiWebs/Telethon/issues/4042.
body = await reader.readexactly(4) body = await reader.readexactly(4)
raise InvalidBufferError(body) raise InvalidBufferError(body)
elif packet_len < 8:
# Currently unknown why packet_len may be less than 8 but not negative.
# Attempting to `readexactly` with less than 0 fails without saying what
# the number was which is less helpful.
raise InvalidBufferError(packet_len_seq)
body = await reader.readexactly(packet_len - 8) body = await reader.readexactly(packet_len - 8)
checksum = struct.unpack('<I', body[-4:])[0] checksum = struct.unpack('<I', body[-4:])[0]