Re: generate_series for timestamptz and time zone problem

From: Andreas 'ads' Scherbaum <ads(at)pgug(dot)de>
To: Gurjeet Singh <gurjeet(at)singh(dot)im>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Przemysław Sztoch <przemyslaw(at)sztoch(dot)pl>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: generate_series for timestamptz and time zone problem
Date: 2023-03-04 00:28:26
Message-ID: a56b83dd-f7f3-ebc3-dd10-0cc9ea3bb9aa@pgug.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 31/01/2023 08:50, Gurjeet Singh wrote:
> On Mon, Jan 30, 2023 at 4:07 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Gurjeet Singh <gurjeet(at)singh(dot)im> writes:
>>> [ generate_series_with_timezone.v6.patch ]
>> The cfbot isn't terribly happy with this. It looks like UBSan
>> is detecting some undefined behavior. Possibly an uninitialized
>> variable?
> It was the classical case of out-of-bounds access. I was trying to
> access 4th argument, even in the case where the 3-argument variant of
> generate_series() was called.
>
> Please see attached v7 of the patch. It now checks PG_NARGS() before
> accessing the optional parameter.
>
> This mistake would've been caught early if there were assertions
> preventing access beyond the number of arguments passed to the
> function. I'll send the assert_enough_args.patch, that adds these
> checks, in a separate thread to avoid potentially confusing cfbot.

Tested this patch on current head.
The patch applies, with a few offsets.

Functionality wise it works as documented, also tried with
"America/New_York" and "Europe/Berlin" as time zone.
The included tests cover both an entire year (including a new year), and
also a DST switch (date_add() for 2021-10-31 in Europe/Warsaw, which is
the date the country switches to standard time).

Minor nitpick: the texts use both "time zone" and "timezone".

Regards,

--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Volunteer Regional Contact, Germany - PostgreSQL Project

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-03-04 00:33:39 Re: Simplify standby state machine a bit in WaitForWALToBecomeAvailable()
Previous Message Jelte Fennema 2023-03-03 23:57:15 Re: running logical replication as the subscription owner