| From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
|---|---|
| To: | Jianghua Yang <yjhjstz(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] Fix wrong argument to SOFT_ERROR_OCCURRED in timestamptz_date |
| Date: | 2026-03-25 06:16:26 |
| Message-ID: | 775ff3bf-01b3-4218-84c0-653b2add1a65@eisentraut.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On 24.03.26 16:44, Jianghua Yang wrote:
> Hi hackers,
>
> I found a small bug in commit e2f289e5b9b ("Make many cast functions
> error safe").
>
> In timestamptz_date(), the SOFT_ERROR_OCCURRED() check mistakenly
> uses fcinfo->args instead of fcinfo->context:
>
> result = timestamptz2date_safe(timestamp, fcinfo->context);
> if (SOFT_ERROR_OCCURRED(fcinfo->args)) /* should be fcinfo->context */
> PG_RETURN_NULL();
>
> fcinfo->args is a NullableDatum[] array, not a Node *. The
> SOFT_ERROR_OCCURRED macro casts its argument to Node * and reads
> the NodeTag field. When given fcinfo->args, it interprets the first
> argument's Datum value (a TimestampTz) as a NodeTag, which will
> almost never match T_ErrorSaveContext. This causes the soft error
> check to always evaluate to false.
>
> As a result, when the timestamptz-to-date conversion encounters an
> overflow in error-safe mode, the function returns a wrong date value
> instead of the expected NULL.
>
> All three sibling functions modified in the same commit (date_timestamp,
> timestamp_date, date_timestamptz) correctly use fcinfo->context.
> This appears to be a copy-paste oversight.
>
> The fix is a one-line change: fcinfo->args → fcinfo->context.
committed the fix, thanks
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2026-03-25 06:17:15 | Re: [PATCH] Fix wrong argument to SOFT_ERROR_OCCURRED in timestamptz_date |
| Previous Message | Michael Paquier | 2026-03-25 06:12:35 | Re: Improve the performance of Unicode Normalization Forms. |