Skip to content

Commit c3953c1

Browse files
authored
Fix reading vectors of bare longs (pyrogram#752)
1 parent eec7ec3 commit c3953c1

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

pyrogram/raw/core/primitives/vector.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from io import BytesIO
2020
from typing import cast, Union, Any
2121

22-
from .int import Int
22+
from .int import Int, Long
2323
from ..list import List
2424
from ..tl_object import TLObject
2525

@@ -30,19 +30,29 @@ class Vector(bytes, TLObject):
3030
# Method added to handle the special case when a query returns a bare Vector (of Ints);
3131
# i.e., RpcResult body starts with 0x1cb5c415 (Vector Id) - e.g., messages.GetMessagesViews.
3232
@staticmethod
33-
def _read(b: BytesIO) -> Union[int, Any]:
33+
def read_bare(b: BytesIO, n: int) -> Union[int, Any]:
34+
left = len(b.read())
35+
size = left // n
36+
b.seek(-left, 1)
37+
3438
try:
3539
return TLObject.read(b)
36-
except ValueError:
40+
except KeyError:
3741
b.seek(-4, 1)
38-
return Int.read(b)
42+
43+
if size == 4:
44+
return Int.read(b)
45+
else:
46+
return Long.read(b)
3947

4048
@classmethod
4149
def read(cls, data: BytesIO, t: Any = None, *args: Any) -> List:
50+
count = Int.read(data)
51+
4252
return List(
4353
t.read(data) if t
44-
else Vector._read(data)
45-
for _ in range(Int.read(data))
54+
else Vector.read_bare(data, count)
55+
for _ in range(count)
4656
)
4757

4858
def __new__(cls, value: list, t: Any = None) -> bytes: # type: ignore

0 commit comments

Comments
 (0)