fix a crash when refreshing headers with a negative unix timestamp, fix #5054 (#5078)

This commit is contained in:
Maximilian Hils 2022-01-18 23:32:38 +01:00 committed by GitHub
parent d47fd3e9c3
commit 53f60c88b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -1185,7 +1185,10 @@ class Response(Message):
d = parsedate_tz(self.headers[i]) d = parsedate_tz(self.headers[i])
if d: if d:
new = mktime_tz(d) + delta new = mktime_tz(d) + delta
self.headers[i] = formatdate(new, usegmt=True) try:
self.headers[i] = formatdate(new, usegmt=True)
except OSError: # pragma: no cover
pass # value out of bounds on Windows only (which is why we exclude it from coverage).
c = [] c = []
for set_cookie_header in self.headers.get_all("set-cookie"): for set_cookie_header in self.headers.get_all("set-cookie"):
try: try:

View File

@ -613,6 +613,11 @@ class TestResponseUtils:
m.side_effect = ValueError m.side_effect = ValueError
r.refresh(n) r.refresh(n)
# Test negative unixtime, which raises on at least Windows.
r.headers["date"] = pre = "Mon, 01 Jan 1601 00:00:00 GMT"
r.refresh(946681202)
assert r.headers["date"] == pre
class TestHTTPFlow: class TestHTTPFlow: