public inbox for [email protected]  
help / color / mirror / Atom feed
From: Masahiko Sawada <[email protected]>
To: [email protected]
Subject: pgsql: Fix timestamp overflow in UUIDv7 implementation.
Date: Fri, 28 Mar 2025 16:39:34 +0000
Message-ID: <[email protected]> (raw)

Fix timestamp overflow in UUIDv7 implementation.

The uuidv7_interval() function previously converted a shifted
microsecond-precision timestamp (64-bit integer) to another 64-bit
integer representing a timestamp with nanosecond precision. This
conversion caused overflow for dates beyond the year 2262. The
millisecond and sub-millisecond parts were then extracted from this
nanosecond-precision timestamp and stored in UUIDv7 values.

With this commit, the millisecond and sub-millisecond parts are stored
directly into the UUIDv7 value without being converted back to a
nanosecond precision timestamp. Following RFC 9562, the timestamp is
stored as an unsigned integer, enabling support for dates up to the
year 10889.

Reported and fixed by Andrey Borodin, with cosmetic changes and
regression tests by me.

Reported-by: Andrey Borodin <[email protected]>
Author: Andrey Borodin <[email protected]>
Discussion: https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a5419bc72e22337a16655aa28e2e20ecb65f65c3

Modified Files
--------------
src/backend/utils/adt/uuid.c       | 34 +++++++++++++++++-----------------
src/test/regress/expected/uuid.out | 15 +++++++++++++++
src/test/regress/sql/uuid.sql      | 12 ++++++++++++
3 files changed, 44 insertions(+), 17 deletions(-)



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: Fix timestamp overflow in UUIDv7 implementation.
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox