Skip to content

Commit

Permalink
catching year overflow ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett authored and davidism committed Mar 9, 2022
1 parent 85b1e3b commit 37f0997
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,8 @@ Version 2.1.1

Unreleased

- Handle date overflow in timed unsign. :pr:`296`


Version 2.1.0
-------------
Expand Down
10 changes: 8 additions & 2 deletions src/itsdangerous/timed.py
Expand Up @@ -38,7 +38,8 @@ def get_timestamp(self) -> int:

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``
Expand Down Expand Up @@ -124,7 +125,12 @@ def unsign(
# 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)

Expand Down

0 comments on commit 37f0997

Please sign in to comment.