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 1x7uy9-00000000nuU-0jiq for pgsql-bugs@arkaria.postgresql.org; Sat, 19 Sep 2026 13:19:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x7uy8-00000004xVj-1xvB for pgsql-bugs@arkaria.postgresql.org; Sat, 19 Sep 2026 13:19:04 +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.98.2) (envelope-from ) id 1x7t3A-00000004dAV-1dIm for pgsql-bugs@lists.postgresql.org; Sat, 19 Sep 2026 11:16: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 1x7t38-00000000BPr-0KhN for pgsql-bugs@lists.postgresql.org; Sat, 19 Sep 2026 11:16:07 +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=LZdzUVd4bOoIkWWchFbmDvMcnnzk/miMULwYhsCofE8=; b=1ul4u1P3gNLKWcJxt4Ik2Cxxt8 9TYAFSHahJRHRm24am+ZQpQzARdVPQ9p4wCH2Oky6q2Q6boxtvwXJ2LmrhOBC6J2jHwKHUEN/gjxs peDKuD/BJPwH58KeFD4eVoFL+IhDW9+WgiB8xqXtWESt7aF2stevWOq0T2JIw8PeIkGGB5w5SYZmi +JEMhOXNQUktQwhACemtwf75spK+k1YchLCdBhjxYIELdB3cG3G+D3O8AF3NccyHjElj3Jnl2t0J9 WfDyB8pDAgNMf+KUllFzrtpLQlRiuPXcmPnCURmDGE9dVJtS8lOvppi9+Ms4p7G+esXpG/yvDwYS7 Dk1jRMjQ==; 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 1x7t36-000VuJ-0L for pgsql-bugs@lists.postgresql.org; Sat, 19 Sep 2026 11:16:06 +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 1x7t34-00000001ea5-36fG for pgsql-bugs@lists.postgresql.org; Sat, 19 Sep 2026 11:16:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19702: decode() accepts Base64 payload after terminal padding To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan@163.com Reply-To: imchifan@163.com, pgsql-bugs@lists.postgresql.org Date: Sat, 19 Sep 2026 11:15:48 +0000 Message-ID: <19702-9ed4a131fcfadb9d@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: 19702 Logged by: Qifan Liu Email address: imchifan@163.com PostgreSQL version: 18.6 Operating system: Linux/amd64 Description: =20 decode() accepts Base64 alphabet characters after terminal '=3D' padding and incorporates them into the decoded bytea value. Once terminal padding completes a Base64 value, only ignorable whitespace may follow. Applications relying on decode() to validate Base64 input may consequently process malformed input as valid data. Steps to reproduce ------------------ Run the following with psql: \set ON_ERROR_STOP on SELECT encode(decode('YQ=3D=3DYg=3D=3D', 'base64'), 'hex') AS decoded_hex; SELECT encode(decode('YQ=3D=3DAAAA', 'base64'), 'hex') AS decoded_hex_after_padding; Actual result ------------- decoded_hex ------------- 6162 (1 row) decoded_hex_after_padding --------------------------- 6100 (1 row) Expected result --------------- Both decode() calls should reject their input with SQLSTATE 22023 because Base64 alphabet characters occur after terminal '=3D' padding. They should = not silently decode the trailing payload. Additional information ---------------------- The issue was reproduced on PostgreSQL 20devel, PostgreSQL 18.6, and PostgreSQL 17.11.