Skip to content

Commit 25494a8

Browse files
authored
Merge pull request #296 from alanhamlett/main
2 parents 3b76264 + 177196d commit 25494a8

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Version 2.1.1
33

44
Unreleased
55

6+
- Handle date overflow in timed unsign. :pr:`296`
7+
68

79
Version 2.1.0
810
-------------

src/itsdangerous/timed.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ def unsign(
124124
# split the value and the timestamp.
125125
if sig_error is not None:
126126
if ts_int is not None:
127-
ts_dt = self.timestamp_to_datetime(ts_int)
127+
try:
128+
ts_dt = self.timestamp_to_datetime(ts_int)
129+
except (ValueError, OSError) as exc:
130+
# Windows raises OSError
131+
raise BadTimeSignature(
132+
"Malformed timestamp", payload=value
133+
) from exc
128134

129135
raise BadTimeSignature(str(sig_error), payload=value, date_signed=ts_dt)
130136

tests/test_itsdangerous/test_timed.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ def test_malformed_timestamp(self, signer):
6666
assert "Malformed" in str(exc_info.value)
6767
assert exc_info.value.date_signed is None
6868

69+
def test_malformed_future_timestamp(self, signer):
70+
signed = b"value.TgPVoaGhoQ.AGBfQ6G6cr07byTRt0zAdPljHOY"
71+
72+
with pytest.raises(BadTimeSignature) as exc_info:
73+
signer.unsign(signed)
74+
75+
assert "Malformed" in str(exc_info.value)
76+
assert exc_info.value.date_signed is None
77+
6978
def test_future_age(self, signer):
7079
signed = signer.sign("value")
7180

0 commit comments

Comments
 (0)