From 6c36a4bc93ec2b09ee3ad65138a42f62a9705105 Mon Sep 17 00:00:00 2001 From: Kenneth Hsu Date: Wed, 23 Oct 2019 19:45:45 -0700 Subject: [PATCH] Avoid possible invalid DateTimeOffset values. When creating a new backup, a value of DateTime.MinValue can be provided to the NormalizeDateTimeToEpochSeconds method. If DateTimeOffset is used, it will convert the provided DateTime to the UTC equivalent, which may result in a value outside of the allowable bounds. This reverts the changes from pull request #3919. This fixes issue #3955. --- Duplicati/Library/Utility/Utility.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Duplicati/Library/Utility/Utility.cs b/Duplicati/Library/Utility/Utility.cs index a3e259e80..662f600e9 100644 --- a/Duplicati/Library/Utility/Utility.cs +++ b/Duplicati/Library/Utility/Utility.cs @@ -957,7 +957,12 @@ namespace Duplicati.Library.Utility /// The input time public static long NormalizeDateTimeToEpochSeconds(DateTime input) { - return (new DateTimeOffset(input)).ToUnixTimeSeconds(); + // Note that we cannot return (new DateTimeOffset(input)).ToUnixTimeSeconds() here. + // The DateTimeOffset constructor will convert the provided DateTime to the UTC + // equivalent. However, if DateTime.MinValue is provided (for example, when creating + // a new backup), this can result in values that fall outside the DateTimeOffset.MinValue + // and DateTimeOffset.MaxValue bounds. + return (long) Math.Floor((NormalizeDateTime(input) - EPOCH).TotalSeconds); } ///