pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix incorrect Datum conversion in timestamptz_trunc_internal()
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix incorrect Datum conversion in timestamptz_trunc_internal()
@ 2025-08-07 02:02  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Paquier @ 2025-08-07 02:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix incorrect Datum conversion in timestamptz_trunc_internal()

The code used a PG_RETURN_TIMESTAMPTZ() where the return type is
TimestampTz and not a Datum.

On 64-bit systems, there is no effect since this just ends up casting
64-bit integers back and forth.  On 32-bit systems, timestamptz is
pass-by-reference.  PG_RETURN_TIMESTAMPTZ() allocates new memory and
returns the address, meaning that the caller could interpret this as a
timestamp value.

The effect is using "date_trunc(..., 'infinity'::timestamptz) will
return random values (instead of the correct return value 'infinity').

Bug introduced in commit d85ce012f99f.

Author: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2d320b6f-b4af-4fbc-9eec-5d0fa15d187b@eisentraut.org
Discussion: https://postgr.es/m/4bf60a84-2862-4a53-acd5-8eddf134a60e@eisentraut.org
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2242b26ce472db9ac69dc71008c566ea9cd3a5fd

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix incorrect Datum conversion in timestamptz_trunc_internal()
@ 2025-08-07 02:02  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Paquier @ 2025-08-07 02:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix incorrect Datum conversion in timestamptz_trunc_internal()

The code used a PG_RETURN_TIMESTAMPTZ() where the return type is
TimestampTz and not a Datum.

On 64-bit systems, there is no effect since this just ends up casting
64-bit integers back and forth.  On 32-bit systems, timestamptz is
pass-by-reference.  PG_RETURN_TIMESTAMPTZ() allocates new memory and
returns the address, meaning that the caller could interpret this as a
timestamp value.

The effect is using "date_trunc(..., 'infinity'::timestamptz) will
return random values (instead of the correct return value 'infinity').

Bug introduced in commit d85ce012f99f.

Author: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/2d320b6f-b4af-4fbc-9eec-5d0fa15d187b@eisentraut.org
Discussion: https://postgr.es/m/4bf60a84-2862-4a53-acd5-8eddf134a60e@eisentraut.org
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/074db8604ad1fa7cd11bffbb4bb5cf9c69c6824b

Modified Files
--------------
src/backend/utils/adt/timestamp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-08-07 02:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-08-07 02:02 pgsql: Fix incorrect Datum conversion in timestamptz_trunc_internal() Michael Paquier <michael@paquier.xyz>
2025-08-07 02:02 pgsql: Fix incorrect Datum conversion in timestamptz_trunc_internal() Michael Paquier <michael@paquier.xyz>

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