From 03ff996ace3cc97ab31dce1358a9a4e80e701fb2 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 29 Apr 2023 12:33:32 +0200 Subject: [PATCH] Improve unhelpful 'readexactly size can not be less than zero' Technically closes #4092, as the error is now properly handled. --- telethon/network/connection/tcpfull.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/telethon/network/connection/tcpfull.py b/telethon/network/connection/tcpfull.py index 5fc5613f..50c5c915 100644 --- a/telethon/network/connection/tcpfull.py +++ b/telethon/network/connection/tcpfull.py @@ -30,6 +30,11 @@ class FullPacketCodec(PacketCodec): # See https://github.com/LonamiWebs/Telethon/issues/4042. body = await reader.readexactly(4) 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) checksum = struct.unpack('