From b1fc26dcb6a9333efd28526afa97274a1ac1ea8f Mon Sep 17 00:00:00 2001 From: Tanner Stirrat Date: Thu, 12 Sep 2024 11:20:35 -0600 Subject: [PATCH] Attempt at test fix --- internal/datastore/postgres/postgres_shared_test.go | 5 ++++- internal/datastore/postgres/revisions.go | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/datastore/postgres/postgres_shared_test.go b/internal/datastore/postgres/postgres_shared_test.go index 62c40797ef..b1933b9613 100644 --- a/internal/datastore/postgres/postgres_shared_test.go +++ b/internal/datastore/postgres/postgres_shared_test.go @@ -1465,7 +1465,10 @@ func StrictReadModeTest(t *testing.T, ds datastore.Datastore) { // Perform a read at a manually constructed revision beyond head, which should fail. badRev := postgresRevision{ snapshot: pgSnapshot{ - xmax: 9999999999999999999, + // NOTE: the struct defines this value as uint64, but the underlying + // revision is defined as an int64, so we run into an overflow issue + // if we try and use a big uint64. + xmax: math.MaxInt64, }, } diff --git a/internal/datastore/postgres/revisions.go b/internal/datastore/postgres/revisions.go index 7be63c26c2..e923f8f4ae 100644 --- a/internal/datastore/postgres/revisions.go +++ b/internal/datastore/postgres/revisions.go @@ -157,14 +157,19 @@ func parseRevisionProto(revisionStr string) (datastore.Revision, error) { xminInt, err := safecast.ToInt64(decoded.Xmin) if err != nil { - return datastore.NoRevision, spiceerrors.MustBugf("Could not cast xmin to int64") + return datastore.NoRevision, spiceerrors.MustBugf("could not cast xmin to int64") } var xips []uint64 if len(decoded.RelativeXips) > 0 { xips = make([]uint64, len(decoded.RelativeXips)) for i, relativeXip := range decoded.RelativeXips { - xips[i] = uint64(xminInt + relativeXip) + xip := xminInt + relativeXip + uintXip, err := safecast.ToUint64(xip) + if err != nil { + return datastore.NoRevision, spiceerrors.MustBugf("could not cast xip to int64") + } + xips[i] = uintXip } }