catch invalid dates, closes #868

This commit is contained in:
Philipp Crocoll
2020-02-15 04:15:35 +01:00
parent e51999ea1f
commit 2b2deb291a

View File

@@ -23,7 +23,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using keepass2android;
#if !KeePassUAP #if !KeePassUAP
using System.Drawing; using System.Drawing;
#endif #endif
@@ -872,7 +872,16 @@ namespace KeePassLib.Serialization
pb = pb8; pb = pb8;
} }
long lSec = MemUtil.BytesToInt64(pb); long lSec = MemUtil.BytesToInt64(pb);
try
{
return new DateTime(lSec * TimeSpan.TicksPerSecond, DateTimeKind.Utc); return new DateTime(lSec * TimeSpan.TicksPerSecond, DateTimeKind.Utc);
}
catch (System.ArgumentOutOfRangeException e)
{
//files might contain bad data, e.g. see #868. Fall back to MinValue
Kp2aLog.Log("Failed to read date from file.");
return DateTime.MinValue;
}
} }
else else
{ {