summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Hamlett <alan.hamlett@gmail.com>2022-03-08 17:43:30 -0800
committerDavid Lord <davidism@gmail.com>2022-03-09 06:17:28 -0800
commit37f09970fa32a330a6660ded3abdb264086531b5 (patch)
treec59afaffc90383fd8214d62ecde38f6767a821ee
parent85b1e3b76e0e37473dc286450ada725cd02981b4 (diff)
downloaditsdangerous-37f09970fa32a330a6660ded3abdb264086531b5.tar.gz
catching year overflow ValueError
-rw-r--r--CHANGES.rst2
-rw-r--r--src/itsdangerous/timed.py10
2 files changed, 10 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index ef811be..8098f8f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,8 @@ Version 2.1.1
Unreleased
+- Handle date overflow in timed unsign. :pr:`296`
+
Version 2.1.0
-------------
diff --git a/src/itsdangerous/timed.py b/src/itsdangerous/timed.py
index 5ea957f..9187a44 100644
--- a/src/itsdangerous/timed.py
+++ b/src/itsdangerous/timed.py
@@ -38,7 +38,8 @@ class TimestampSigner(Signer):
def timestamp_to_datetime(self, ts: int) -> datetime:
"""Convert the timestamp from :meth:`get_timestamp` into an
- aware :class`datetime.datetime` in UTC.
+ aware :class`datetime.datetime` in UTC. Raises :exc:`.ValueError`
+ if the timestamp is too far in the past or future for Python.
.. versionchanged:: 2.0
The timestamp is returned as a timezone-aware ``datetime``
@@ -124,7 +125,12 @@ class TimestampSigner(Signer):
# split the value and the timestamp.
if sig_error is not None:
if ts_int is not None:
- ts_dt = self.timestamp_to_datetime(ts_int)
+ try:
+ ts_dt = self.timestamp_to_datetime(ts_int)
+ except ValueError as exc:
+ raise BadTimeSignature(
+ "Malformed timestamp", payload=value
+ ) from exc
raise BadTimeSignature(str(sig_error), payload=value, date_signed=ts_dt)