pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 125atishprak@gmail.com
Subject: BUG #19843: decode(..., 'base64url') returns an extra byte for "ab="
Date: Sat, 07 Nov 2026 14:12:16 +0000
Message-ID: <19843-ebef332578fa09da@postgresql.org> (raw)

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:        

decode() with the new base64url format returns a spurious trailing byte when
the input has one '=' where two would be needed:

    SELECT decode('ab', 'base64url');    -- \x69
    SELECT decode('ab==', 'base64url');  -- \x69
    SELECT decode('ab=', '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 '=' sets end = 1 and advances pos
to
3. The input then ends, and the "url && pos == 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.







view thread (4+ messages)  latest in thread

Message-ID: <19843-ebef332578fa09da@postgresql.org>
Permalink:  ../19843-ebef332578fa09da@postgresql.org/
Also on:    postgresql.org/message-id/19843-ebef332578fa09da@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, 125atishprak@gmail.com
  Subject: Re: BUG #19843: decode(..., 'base64url') returns an extra byte for "ab="
  In-Reply-To: <19843-ebef332578fa09da@postgresql.org>
  References: <19843-ebef332578fa09da@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox