Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x4ddY-007IBp-22 for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Sep 2026 12:12:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4ddX-005XZh-1u for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Sep 2026 12:12:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3aCc-001xCS-2w for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:20:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x3aCa-00000004RSD-2uKI for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:20:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=+ooKFM9fVCoxnKkvNTc96tApWGQqzzdToFg0HKFLdTY=; b=wWJ7CpvknC0AqJWwsCzGTGx5b+ b4uUDAXIjXZxF1dpg+vX/9BHRYWk8bTRG8RmAaUkLJOM3IWMvsGCl+NAD5+OZKPrdnzgLZvUa4AWf vqcEmizCYh0O/TvpCps0RMTwQmlQsuG2Lg+j2+gBV2+r//Hx5+3k71msDK08LwvEemH/VLPrpnL15 +MyKgPnPtPeQ1fFlx/QpAYUIIHRGVVDH7hwZxNMs+2IPhY/Bvv3bSl/thvcJldJ3fTJBUUi52Iyab uSIHN4Fyn74s9O0IvRUpo94X5yv2qfPYGdqfQm0Zj2rqnduAT3C0AWUsvk37jQU5/9nB1ewyvcqfx S7qxOHEw==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3aCa-00DTdl-1T for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:20:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x3aCZ-00000000gKX-1XLA for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:20:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: =?utf-8?q?BUG_=2319677=3A_Silent_int64=E2=86=92int32_Truncation_in_timestamp=5Fizone=28=29_Produces_Wrong_Timestamps?= To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 1950233439@qq.com Reply-To: 1950233439@qq.com, pgsql-bugs@lists.postgresql.org Date: Mon, 07 Sep 2026 14:19:49 +0000 Message-ID: <19677-0c8e10df414db679@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19677 Logged by: Tianyu Shi Email address: 1950233439@qq.com PostgreSQL version: 19beta3 Operating system: Ubuntu22.04 Description: =20 ### Summary In `src/backend/utils/adt/timestamp.c`, `timestamp_izone()` (line 6443) and `timestamptz_izone()` (line 6712) assign `zone->time / USECS_PER_SEC` =E2= =80=94 a 64-bit value =E2=80=94 directly into a 32-bit `int tz` with no range check.= When the interval argument exceeds ~596,523 hours, the second count surpasses INT32_MAX (2,147,483,647), high bits are silently discarded, and the offset sign flips. The corrupted offset is passed to `dt2local()`, causing `AT TIME ZONE` to return a timestamp over 136 years wrong with no error, enabling forgery of audit log timestamps and bypass of time-based application security policies. ### PoC No superuser required; any authenticated user can trigger this with a single SELECT. ```sql -- 596524 * 3600 =3D 2,147,486,400 seconds > INT32_MAX; the int32 wrap flips the offset sign. SELECT '2024-01-01 00:00:00'::timestamp AT TIME ZONE '596524 hours'::interval AS actual_result, TIMESTAMP '2024-01-01 00:00:00' - INTERVAL '596524 hours' AS expected_result, ( '2024-01-01 00:00:00'::timestamp AT TIME ZONE '596524 hours'::interval - (TIMESTAMP '2024-01-01 00:00:00' - INTERVAL '596524 hours') ) AS difference; ``` ### Result Expected: `1955-12-13 20:00:00` (2024-01-01 shifted back 596,524 hours). Actual: `2092-01-19 10:28:16+08` (shifted *forward* ~68 years instead). Difference: `49710 days 13:58:16` (~136 years off); no error is raised. Key output from verification: ``` 596524 hours (overflow) | 2092-01-19 10:28:16+08 | 1955-12-13 20:00:00 | MISMATCH - truncation bug confirmed ``` Root cause: `2147486400 mod 2^32 - 2^32 =3D -2147480896` =E2=80=94 the posi= tive offset wraps to a large negative value, inverting the shift direction entirely while `IS_VALID_TIMESTAMP` passes the in-range result silently.