Skip to content

Commit ebb1a33

Browse files
committed
Fixing when cookie expiration date received by .NET exceeds max DateTime
When receiving a cookie via the JSON wire protocol, the expiration date is represented as the number of seconds after 12:00:00 AM January 1, 1970 GMT. When a number greater than or equal 253402300800, this is larger than the maximum value of .NET's DateTime value. This change catches the ArgumentOutOfRangeException and forcibly sets the expiration to DateTime.MaxValue (12:59:59 PM December 31, 9999 GMT). Fixes issue #5692.
1 parent 91ee467 commit ebb1a33

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

dotnet/src/webdriver/Remote/RemoteCookieJar.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ private ReadOnlyCollection<Cookie> GetAllCookies()
154154
long seconds = 0;
155155
if (long.TryParse(cookie["expiry"].ToString(), out seconds))
156156
{
157-
expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds).ToLocalTime();
157+
try
158+
{
159+
expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(seconds).ToLocalTime();
160+
}
161+
catch (ArgumentOutOfRangeException)
162+
{
163+
expires = DateTime.MaxValue.ToLocalTime();
164+
}
158165
}
159166
}
160167

0 commit comments

Comments
 (0)