BUG #19714: pgcrypto pgp_sym_encrypt accepts nonnumeric s2k-mode as mode 0

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: imchifan(at)163(dot)com
Subject: BUG #19714: pgcrypto pgp_sym_encrypt accepts nonnumeric s2k-mode as mode 0
Date: 2026-09-22 16:05:30
Message-ID: 19714-2c7439b39f73bde9@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19714
Logged by: Qifan Liu
Email address: imchifan(at)163(dot)com
PostgreSQL version: 18.6
Operating system: Linux on amd64
Description:

pgp_sym_encrypt accepts the malformed option s2k-mode=not_a_number and
produces usable ciphertext. The documented s2k-mode values are numeric modes
0, 1, and 3, so nonnumeric text should be rejected rather than silently
selecting mode 0. This can cause encryption to use a different string-to-key
mode than the caller specified. The impact is localized to pgcrypto option
validation.

Steps to reproduce
------------------
CREATE EXTENSION pgcrypto;

SELECT pgp_sym_decrypt(
pgp_sym_encrypt('payload',
'key',
's2k-mode=not_a_number'),
'key') = 'payload' AS malformed_s2k_mode_accepted;

Actual result
-------------
malformed_s2k_mode_accepted
-----------------------------
t
(1 row)

The malformed value is accepted, and the produced ciphertext decrypts
successfully.

Expected result
---------------
pgp_sym_encrypt should reject s2k-mode=not_a_number with an error because
s2k-mode accepts only the documented numeric values. It should not interpret
malformed text as mode 0 or produce ciphertext.

Additional information
----------------------
The issue was reproduced on PostgreSQL 20devel, PostgreSQL 18.6, and
PostgreSQL 17.11.
Inference: the behavior is consistent with numeric conversion that maps text
without a valid numeric prefix to zero before validating the resulting mode.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2026-09-22 16:10:04 BUG #19715: pg_restore_attribute_stats() rejects range statistics for a domain over int4multirange
Previous Message PG Bug reporting form 2026-09-22 16:01:34 BUG #19713: WindowAgg qual pushdown gives wrong partition count when scale(numeric) distinguishes equal values