From bc213f6ffb4c3c6347c0e954f48df4c16c21426b Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 16 Feb 2025 18:06:58 +0300 Subject: [PATCH] vfs: torrent - fix date/time handling Especially with overflow d/t; esp on w32. Closes MidnightCommander/mc#213 . Signed-off-by: Oleg Broytman Signed-off-by: Yury V. Zaytsev --- src/vfs/extfs/helpers/torrent.in | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) mode change 100644 => 100755 src/vfs/extfs/helpers/torrent.in diff --git a/src/vfs/extfs/helpers/torrent.in b/src/vfs/extfs/helpers/torrent.in old mode 100644 new mode 100755 index 4e7a4236ca..08b1b5911c --- a/src/vfs/extfs/helpers/torrent.in +++ b/src/vfs/extfs/helpers/torrent.in @@ -425,18 +425,23 @@ def decode_torrent(): def decode_datetime_asc(dt): try: - return asctime(localtime(float(dt))) - except ValueError: + lt = localtime(float(dt)) + Y = lt[0] + if Y > 9999: + raise ValueError + except (OSError, ValueError): return datetime.max.ctime() + else: + return asctime(lt) def decode_datetime(dt): try: - Y, m, d, H, M = localtime(float(dt))[0:5] - except ValueError: - return datetime.max.ctime() - if Y > 9999: - Y = 9999 + Y, m, d, H, M = localtime(float(dt))[:5] + if Y > 9999: + raise ValueError + except (OSError, ValueError): + Y, m, d, H, M = datetime.max.timetuple()[:5] return "%02d-%02d-%d %02d:%02d" % (m, d, Y, H, M)