From 730a8ed3800c84fb623a10095b0fe16c7596db6a Mon Sep 17 00:00:00 2001 From: ChoiHwaa <107089378+ChoiHwaa@users.noreply.github.com> Date: Tue, 14 Jun 2022 22:59:11 +0100 Subject: [PATCH] Fix serialize_datetime (edits) Add checks to prevent `struct.pack()` from failing and for users to not use dates outside the ranges of 1970 to 2038. --- telethon/tl/tlobject.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telethon/tl/tlobject.py b/telethon/tl/tlobject.py index 20587fa9..e625e236 100644 --- a/telethon/tl/tlobject.py +++ b/telethon/tl/tlobject.py @@ -135,7 +135,11 @@ class TLObject: dt = int(dt.total_seconds()) except OSError: dt = 0 - + + # 2145916800 is the date 2038, 1, 1. + if dt > 2145916800: + raise ValueError("Date is outside the range of valid values.") + if isinstance(dt, int): return struct.pack('