From: | Алена Васильева <gorcom2012(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | [PATCH] Handle out-of-range timestamps in timestamptz_to_str() |
Date: | 2025-10-15 08:50:21 |
Message-ID: | CABg3sZroJmuF+-c8Tswd4rNMVJEHVL94jttvoxBqA04PnJHLgw@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello,
The function timestamptz_to_str() in src/bin/pg_waldump/compat.c does not
handle the case when localtime() returns NULL, which can happen for
timestamps
that are out of the supported time_t range on some platforms.
This patch adds a simple check for a NULL return value and ensures that the
function returns a clear error string "(timestamp out of range)" instead of
causing undefined behavior or a crash.
Best regards,
Eugeny Goryachev
*Patch attached for Postgres 16.6:*
From b443fb1a5b3b0f0ffb419c2eb7a7375c9d5b990e Mon Sep 17 00:00:00 2001
From: Eugeny Goryachev <gorcom2012(at)gmail(dot)com>
Date: Wed, 15 Oct 2025 12:41:10 +0400
Subject: [PATCH] Fix timestamptz_to_str() for out-of-range timestamps
---
src/bin/pg_waldump/compat.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/bin/pg_waldump/compat.c b/src/bin/pg_waldump/compat.c
index 2aca73f2e93..825311b1bd4 100644
--- a/src/bin/pg_waldump/compat.c
+++ b/src/bin/pg_waldump/compat.c
@@ -54,6 +54,12 @@ timestamptz_to_str(TimestampTz t)
time_t result = (time_t) timestamptz_to_time_t(t);
struct tm *ltime = localtime(&result);
+ if (!ltime)
+ {
+ strlcpy(buf, "(timestamp out of range)", sizeof(buf));
+ return buf;
+ }
+
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", ltime);
strftime(zone, sizeof(zone), "%Z", ltime);
--
2.43.0
Attachment | Content-Type | Size |
---|---|---|
0001-Fix-timestamptz_to_str-for-out-of-range-timestamps.patch | text/x-patch | 844 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Álvaro Herrera | 2025-10-15 08:51:42 | Re: Implement waiting for wal lsn replay: reloaded |
Previous Message | Xuneng Zhou | 2025-10-15 08:43:29 | Re: Improve read_local_xlog_page_guts by replacing polling with latch-based waiting |