From: Kiran Rangoon <kiranrangoon0@gmail.com>
To: util-linux@vger.kernel.org
Cc: Kiran Rangoon <kiranrangoon0@gmail.com>
Subject: [PATCH v2] libuuid: Fix pre-1970 UUID v1 timestamp wraparound
Date: Sat, 13 Dec 2025 20:01:08 -0500 [thread overview]
Message-ID: <20251214010108.29535-1-kiranrangoon0@gmail.com> (raw)
In-Reply-To: <20251213200410.31256-1-kiranrangoon0@gmail.com>
gregorian_to_unix now returns -1 and sets errno=EOVERFLOW
for timestamps before the Unix epoch. uuid_time_v1 and uuid_time_v6
now use signed arithmetic to prevent unsigned wraparound.
This fixes uuidparse displaying far-future dates for historical UUIDs.
The regression test has been updated to show actual result instead of hardcoded wrong
date.
Example output:
$ ./build/uuidparse bf2eb110-d788-1003-aa59-ce1e9e293641
Before:
60041-08-13 16:41:36,271592-04:00
After:
1969-12-31 19:00:00,000000-05:00
Handling negative timestamps gracefully would require broader changes, so I’ve kept this patch focused on preventing pre-1970 wraparound.
Signed-off-by: Kiran Rangoon <kiranrangoon0@gmail.com>
---
libuuid/src/uuid_time.c | 15 +++++++++++----
tests/expected/uuid/uuidparse | 2 +-
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/libuuid/src/uuid_time.c b/libuuid/src/uuid_time.c
index c7516152b..f0d2c8f36 100644
--- a/libuuid/src/uuid_time.c
+++ b/libuuid/src/uuid_time.c
@@ -60,15 +60,22 @@
/* prototype to make compiler happy */
time_t __uuid_time(const uuid_t uu, struct timeval *ret_tv);
-static uint64_t gregorian_to_unix(uint64_t ts)
+static int64_t gregorian_to_unix(uint64_t ts)
{
- return ts - ((((uint64_t) 0x01B21DD2) << 32) + 0x13814000);
+ const uint64_t offset = 0x01B21DD213814000ULL;
+
+ if (ts < offset) {
+ errno = EOVERFLOW;
+ return -1;
+ }
+
+ return ts - offset;
}
static void uuid_time_v1(const struct uuid *uuid, struct timeval *tv)
{
uint32_t high;
- uint64_t clock_reg;
+ int64_t clock_reg;
high = uuid->time_mid | ((uuid->time_hi_and_version & 0xFFF) << 16);
clock_reg = uuid->time_low | ((uint64_t) high << 32);
@@ -80,7 +87,7 @@ static void uuid_time_v1(const struct uuid *uuid, struct timeval *tv)
static void uuid_time_v6(const struct uuid *uuid, struct timeval *tv)
{
- uint64_t clock_reg;
+ int64_t clock_reg;
clock_reg = uuid->time_low;
clock_reg <<= 16;
diff --git a/tests/expected/uuid/uuidparse b/tests/expected/uuid/uuidparse
index 9edb05e4e..0f521a760 100644
--- a/tests/expected/uuid/uuidparse
+++ b/tests/expected/uuid/uuidparse
@@ -11,7 +11,7 @@ UUID VARIANT TYPE TIME
00000000-0000-3000-8000-000000000000 DCE name-based
00000000-0000-4000-8000-000000000000 DCE random
00000000-0000-5000-8000-000000000000 DCE sha1-based
-00000000-0000-6000-8000-000000000000 DCE time-v6 60038-03-11 05:36:10,955161+00:00
+00000000-0000-6000-8000-000000000000 DCE time-v6 1970-01-01 00:00:00,000000+00:00
00000000-0000-0000-d000-000000000000 Microsoft
00000000-0000-1000-d000-000000000000 Microsoft
00000000-0000-2000-d000-000000000000 Microsoft
--
2.47.3
next prev parent reply other threads:[~2025-12-14 1:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-13 20:04 [PATCH] libuuid: Fix pre-1970 UUID v1 timestamp wraparound Kiran Rangoon
2025-12-13 23:36 ` Thomas Weißschuh
2025-12-14 1:01 ` Kiran Rangoon [this message]
2025-12-16 13:08 ` [PATCH v2] " Thomas Weißschuh
2025-12-16 20:40 ` Kiran
2025-12-16 23:21 ` Thomas Weißschuh
2025-12-17 20:42 ` [PATCH v3 1/2] libuuid: Refactor UUID time conversion for pre-epoch dates Kiran Rangoon
2025-12-17 20:59 ` Kiran Rangoon
2025-12-18 21:31 ` Kiran Rangoon
2025-12-19 11:40 ` Thomas Weißschuh
2025-12-23 18:00 ` [PATCH v4 0/4] libuuid: Fix pre-1970 UUID timestamp overflow Kiran Rangoon
2025-12-23 18:00 ` [PATCH v4 1/4] libuuid: simplify gregorian-to-unix offset calculation Kiran Rangoon
2025-12-23 18:00 ` [PATCH v4 2/4] libuuid: refactor gregorian_to_unix to populate timeval directly Kiran Rangoon
2025-12-23 18:03 ` [PATCH v4 1/4] libuuid: simplify gregorian-to-unix offset calculation Kiran Rangoon
2025-12-23 18:22 ` [PATCH v4 0/4] libuuid: Fix pre-1970 UUID timestamp overflow Thomas Weißschuh
2025-12-28 8:47 ` Thomas Weißschuh
2025-12-23 18:04 ` [PATCH v4 3/4] libuuid: fix timestamp overflow for pre-1970 dates Kiran Rangoon
2025-12-23 18:05 ` [PATCH v4 4/4] tests: correct UUID timestamp test expectations Kiran Rangoon
2025-12-17 11:01 ` [PATCH v2] libuuid: Fix pre-1970 UUID v1 timestamp wraparound Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251214010108.29535-1-kiranrangoon0@gmail.com \
--to=kiranrangoon0@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox