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.98.2) (envelope-from ) id 1xPjB6-00000000rgR-2gGJ for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Nov 2026 16:22:06 +0000 Received: from localhost ([127.0.0.1]:57122 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xPirG-000000049lg-04uD for pgsql-bugs@arkaria.postgresql.org; Sat, 07 Nov 2026 16:01:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:35850) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xPhAJ-00000003ad3-3gLM for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 14:13:08 +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 1xPhAG-00000000ida-34tf for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 14:13: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=K37RHZue57zZ0lV6PtMcWPrC6MMePxQzFoWoYePggkg=; b=N9NCV76llfW/vZ8QuMrRH3vBsN sCF1dPTEW7qFpsRYtfN6kH/a8g04A4PATEHUct0XjNMcupzzQok8LzWlJ28D6BRwhjb8HrDwvr+Lg G/IuO+BVcwEO5UfSqRxjNNntDtUpC6h0pEDBKVGa1W5Yksn8Ym3RmJ+IKOYTcWrQI9pWAy27AbCwy tpb+et22ED5Q7Hc+ljD7oj4zD1dgHDh8PQwZuMRDiT7kIgFQtAq66ExkeXhKy5ht/hALeb0ASNEno bkuKg5mi6047Yt1gnlycgeLOxoSDWZcvAAsk2EcVIvsrRnDOMrYeQTkPEUISKF5UhRZx/t6cuvenN uXQ9+hmA==; 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.98.2) (envelope-from ) id 1xPhAH-000000020SP-1Xms for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 14:13:05 +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 1xPhAF-000000053iE-1lzQ for pgsql-bugs@lists.postgresql.org; Sat, 07 Nov 2026 14:13:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19843: decode(..., 'base64url') returns an extra byte for "ab=" To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: 125atishprak@gmail.com Reply-To: 125atishprak@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sat, 07 Nov 2026 14:12:16 +0000 Message-ID: <19843-ebef332578fa09da@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: 19843 Logged by: Atish Prakash Email address: 125atishprak@gmail.com PostgreSQL version: 19rc1 Operating system: Linux x86_64 Description: =20 decode() with the new base64url format returns a spurious trailing byte when the input has one '=3D' where two would be needed: SELECT decode('ab', 'base64url'); -- \x69 SELECT decode('ab=3D=3D', 'base64url'); -- \x69 SELECT decode('ab=3D', 'base64url'); -- \x69b0 Expected: the third query returns \x69, like the other two, or raises an error. The base64 format raises "invalid base64 end sequence" for the same input. The extra byte 0xb0 comes from the leftover bits of 'b' and the padding, and is not data encoded in the input. Cause: in pg_base64_decode_internal(), the '=3D' sets end =3D 1 and advance= s pos to 3. The input then ends, and the "url && pos =3D=3D 3" branch emits two bytes without looking at end. A possible patch is attached (0001-fix-base64url-decode-short-padding.patch). It makes the result \x69. Rejecting the input would also be reasonable, and I have no preference. Regression tests pass with it on master; it adds no new test. Found with semantic differential tests. I reproduced and checked the result myself.