From b9f20d2c79c1c27fb11aff296ec63b78683a8c38 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Thu, 21 May 2020 21:03:41 +0200 Subject: [PATCH] qt locktimeedit: fix max timestamp platform-dependent crash fixes #6170 --- electrum/gui/qt/locktimeedit.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/electrum/gui/qt/locktimeedit.py b/electrum/gui/qt/locktimeedit.py index 3280cff4e..53232ac2a 100644 --- a/electrum/gui/qt/locktimeedit.py +++ b/electrum/gui/qt/locktimeedit.py @@ -146,8 +146,21 @@ class LockTimeHeightEdit(LockTimeRawEdit): painter.drawText(textRect, Qt.AlignRight | Qt.AlignVCenter, "height") +def get_max_allowed_timestamp() -> int: + ts = NLOCKTIME_MAX + # Test if this value is within the valid timestamp limits (which is platform-dependent). + # see #6170 + try: + datetime.fromtimestamp(ts) + except (OSError, OverflowError): + ts = 2 ** 31 - 1 # INT32_MAX + datetime.fromtimestamp(ts) # test if raises + return ts + + class LockTimeDateEdit(QDateTimeEdit, _LockTimeEditor): min_allowed_value = NLOCKTIME_BLOCKHEIGHT_MAX + 1 + max_allowed_value = get_max_allowed_timestamp() def __init__(self, parent=None): QDateTimeEdit.__init__(self, parent)