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 1x4dbn-007IB0-2J for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Sep 2026 12:10:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4dbm-005SyN-20 for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Sep 2026 12:10:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3a04-001stq-1B for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:07:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x3a02-00000003PuD-0maW for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:07:08 +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=CEGPUHR9mQneVg17gMRs+Yza9xR+aJSLdidCdB8eCaI=; b=Vyl/VtnmqWEDYWwAnf1iqUQp7i f1Elijmf/m+/VA8HOEJqHW6SPE3MgJha69YF6NfvpTNwSHZlry83MyVzYKOrisYfawIfTuyoAidat aWTHq3ayxMRqNHIkVDGSvaJ5WQ71FJstT8VVLu0TEIG+9dpOV+6smpaJy8EMkVD2LgBpsuVjZXUuE x10VHuMz4AHu5GcuaG9GgdH1WovUKRe+ylegndiw2jdIPiTimF0IafOfyloldg6tlXc5ses2wxqLB Wk8AeHiHUyWRna1rJsxULoKDeH70kXlQlap4b2hKtlchIvBttksFA7hx0PBlaS2YezYul6nAd6QNI eTGc8riA==; 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 1x3a00-00DTN9-2x for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:07: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 1x3Zzz-00000000fse-3LDS for pgsql-bugs@lists.postgresql.org; Mon, 07 Sep 2026 14:07:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19670: Silent Integer Overflow in time_pl_interval() Returns Wrong Time Value 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:06:53 +0000 Message-ID: <19670-c4e56832fa6686f8@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: 19670 Logged by: Tianyu Shi Email address: 1950233439@qq.com PostgreSQL version: 19beta3 Operating system: Ubuntu22.04 Description: =20 ### Summary `time_pl_interval()` in `src/backend/utils/adt/date.c` (lines 2174=E2=80=93= 2195) silently produces incorrect results when adding a near-maximal interval to a time value. The infinity guard (`INTERVAL_NOT_FINITE`) requires all three interval fields to simultaneously hold their extreme values, so an interval such as `'9223372036854 seconds'` (where `span->time =3D 922337203685400000= 0`, slightly below `INT64_MAX`) bypasses the check entirely. The subsequent unchecked addition `result =3D time + span->time` overflows signed 64-bit integer arithmetic (C undefined behavior), returning a garbage `TimeADT` with no error raised. Applications relying on correct time arithmetic for security decisions =E2=80=94 session expiry, scheduling windows, access-time enforcement =E2=80=94 may silently receive a corrupted value and act on it. ### PoC Any authenticated database user can trigger the overflow with a single SQL statement; no special privileges are required. ```sql SELECT '23:59:59.999999'::time + interval '9223372036854 seconds'; ``` To run against the local build: ```sql -- Connect: ./build/bin/psql -h ./build/run -p 5432 postgres SELECT '23:59:59.999999'::time + interval '9223372036854 seconds' AS actual_result, make_time(0, 0, 0) + 24053999999::bigint * interval '1 microsecond' AS expected_result, CASE WHEN ('23:59:59.999999'::time + interval '9223372036854 seconds') !=3D (make_time(0, 0, 0) + 24053999999::bigint * interval '1 microsecond') THEN 'MISMATCH: Integer overflow confirmed - result is WRONG' ELSE 'MATCH: No overflow detected' END AS verdict; ``` ### Result Expected output (correct modular arithmetic): `06:40:53.999999`. Actual output observed: `19:59:04.448383` =E2=80=94 an overflow-corrupted v= alue returned without any error or warning. ``` actual_result | expected_result | verdict -----------------+-----------------+---------------------------------------= ----------------- 19:59:04.448383 | 06:40:53.999999 | MISMATCH: Integer overflow confirmed - result is WRONG ``` The semantic invariant `(time + interval) mod USECS_PER_DAY` is violated. No exception is raised, so callers cannot distinguish a correct result from a corrupted one.