From 48075713527b4918a53e4a0f130baea994daa117 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 25 Jul 2023 20:39:48 +0900 Subject: [PATCH] pkg/epoch: fix Y2038 on 32-bit hosts `strconv.Itoa(int(tm.Unix()))` rounds the time to 32-bit int on 32-bit hosts Signed-off-by: Akihiro Suda --- pkg/epoch/epoch.go | 2 +- pkg/epoch/epoch_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/epoch/epoch.go b/pkg/epoch/epoch.go index 1e4e06c20..e0a804ef5 100644 --- a/pkg/epoch/epoch.go +++ b/pkg/epoch/epoch.go @@ -73,7 +73,7 @@ func ParseSourceDateEpoch(sourceDateEpoch string) (*time.Time, error) { // SetSourceDateEpoch sets the SOURCE_DATE_EPOCH env var. func SetSourceDateEpoch(tm time.Time) { - _ = os.Setenv(SourceDateEpochEnv, strconv.Itoa(int(tm.Unix()))) + _ = os.Setenv(SourceDateEpochEnv, fmt.Sprintf("%d", tm.Unix())) } // UnsetSourceDateEpoch unsets the SOURCE_DATE_EPOCH env var. diff --git a/pkg/epoch/epoch_test.go b/pkg/epoch/epoch_test.go index 5b3cdb8d1..2d2c29c94 100644 --- a/pkg/epoch/epoch_test.go +++ b/pkg/epoch/epoch_test.go @@ -17,9 +17,9 @@ package epoch import ( + "fmt" "os" "runtime" - "strconv" "testing" "time" @@ -85,7 +85,7 @@ func TestSourceDateEpoch(t *testing.T) { require.NoError(t, err) require.True(t, vp.Equal(sourceDateEpoch.UTC())) - vp, err = ParseSourceDateEpoch(strconv.Itoa(int(sourceDateEpoch.Unix()))) + vp, err = ParseSourceDateEpoch(fmt.Sprintf("%d", sourceDateEpoch.Unix())) require.NoError(t, err) require.True(t, vp.Equal(sourceDateEpoch))