From c3953c18caa3364a2f11b2626349172fe93b1160 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 10 Sep 2021 20:57:06 +0200 Subject: [PATCH] Fix reading vectors of bare longs (#752) --- pyrogram/raw/core/primitives/vector.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/pyrogram/raw/core/primitives/vector.py b/pyrogram/raw/core/primitives/vector.py index 5b2f9ba6..bfcd1b28 100644 --- a/pyrogram/raw/core/primitives/vector.py +++ b/pyrogram/raw/core/primitives/vector.py @@ -19,7 +19,7 @@ from io import BytesIO from typing import cast, Union, Any -from .int import Int +from .int import Int, Long from ..list import List from ..tl_object import TLObject @@ -30,19 +30,29 @@ class Vector(bytes, TLObject): # Method added to handle the special case when a query returns a bare Vector (of Ints); # i.e., RpcResult body starts with 0x1cb5c415 (Vector Id) - e.g., messages.GetMessagesViews. @staticmethod - def _read(b: BytesIO) -> Union[int, Any]: + def read_bare(b: BytesIO, n: int) -> Union[int, Any]: + left = len(b.read()) + size = left // n + b.seek(-left, 1) + try: return TLObject.read(b) - except ValueError: + except KeyError: b.seek(-4, 1) - return Int.read(b) + + if size == 4: + return Int.read(b) + else: + return Long.read(b) @classmethod def read(cls, data: BytesIO, t: Any = None, *args: Any) -> List: + count = Int.read(data) + return List( t.read(data) if t - else Vector._read(data) - for _ in range(Int.read(data)) + else Vector.read_bare(data, count) + for _ in range(count) ) def __new__(cls, value: list, t: Any = None) -> bytes: # type: ignore