1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00
Commit Graph

65042 Commits

Author SHA1 Message Date
Fujii Masao
d6bf0ab170 Add common LSN parser for user-supplied locations
pg_waldump (--start/--end), pg_recvlogical (--startpos/--endpos), and
pg_receivewal (--endpos) parsed user-supplied WAL locations with
sscanf("%X/%08X").  That accepts several forms rejected by pg_lsn input
and can proceed with a different location than the user specified:
overlong components, trailing characters, leading whitespace, signs, and
0x prefixes.

Add pg_parse_lsn() to src/common and use it for those command-line
options.  The helper accepts the pg_lsn text syntax only: one to eight
hexadecimal digits, a slash, one to eight hexadecimal digits, and no
trailing characters.  Each frontend tool keeps its existing error
message.

Use the same helper from pg_lsn_in_safe(), leaving only backend-specific
soft error reporting there.  This keeps frontend command-line validation
and backend pg_lsn input tied to one parser.

Bug: #19598
Reported-by: Michael Malis <malis@pgrust.com>
Author: Zexin Li <lizi.openmind@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/19598-aa67c8f4331611b4@postgresql.org
2026-08-12 17:03:46 +09:00
Daniel Gustafsson
2eb9a8e84a Use per-query timeout in subscription test
A buildfarm failure in subscription/038_walsnd_shutdown_timeout was
diagnosed to the background psql session timing out due to a backup
taking a long time.  The session was using a single timeout for all
queries, so switch to resetting the timer for each query to make it
survive slow backups due to constrained buildfarm machines.

Backpatch to v19 where the test was introduced.

Author: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/OS9PR01MB12149AA18EEA475D2AA22FD3BF5D12@OS9PR01MB12149.jpnprd01.prod.outlook.com
Backpatch-through: 19
2026-08-12 09:41:44 +02:00
Michael Paquier
6828b03b06 Fix poll_query_until() timeout handling with an undefined query in Cluster.pm
On timeout, poll_query_until() would fail to print its report when
"$query" was undefined.  Instead of the expected report, this prevented
the contents of stdout and stderr from being shown.

Note that some of the in-core tests use an undefined query for
connection-only polls.

Author: Bryan Green <dbryan.green@gmail.com>
Reviewed-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
Discussion: https://postgr.es/m/0f515c6d-6032-4c5f-80ac-5c78faae9522@gmail.com
Backpatch-through: 14
2026-08-12 16:23:04 +09:00
Amit Kapila
cc1ea710dc Remove unnecessary list_free() calls in OpenTableList().
OpenTableList() is invoked at most once per DDL statement, from
CreatePublication() and AlterPublicationTables(), and everything it
builds (relids, relids_with_rf, and relids_with_collist) is allocated
in the command's own memory context. That context is reclaimed as
soon as the command finishes, so explicitly freeing relids and
relids_with_rf here served no purpose.

Reported-by: Peter Smith <smithpb2250@gmail.com>
Suggested-by: Tom Lane <tgl@sss.pgh.pa.us>
Author: Peter Smith <smithpb2250@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Reviewed-by: surya poondla <suryapoondla4@gmail.com>
Discussion: https://postgr.es/m/CAHut+Pt3bgyt==d6GCj=p9qu4sVSH_KQWLN7cMaH0RdJCO-K_Q@mail.gmail.com
2026-08-12 11:28:30 +05:30
Fujii Masao
33c77cfad3 Avoid unnecessary matview populated-state updates
REFRESH MATERIALIZED VIEW currently calls SetMatViewPopulatedState()
even when the materialized view's relispopulated value already matches
the state requested by the command.  That performs a catalog update of
pg_class without changing the visible state of the materialized view.

The extra update creates a dead pg_class tuple and causes the usual
catalog-update side effects, including relcache invalidation and WAL,
for no semantic benefit.  The effect is especially visible for
REFRESH MATERIALIZED VIEW CONCURRENTLY, where the refresh updates the
materialized view contents with DML and otherwise need not change
pg_class just to keep relispopulated set to true.

Check the current populated state before calling SetMatViewPopulatedState(),
and update pg_class only when the value would actually change.  This
preserves the required state transitions for WITH DATA and WITH NO DATA
while avoiding catalog churn for repeated refreshes that leave the
populated state unchanged.

Author: ChangAo Chen <cca5507@qq.com>
Reviewed-by: Zizhuan Liu <44973863@qq.com>
Reviewed-by: Adam Brusselback <adambrusselback@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/tencent_DF2D8533B5412908326F7806075B7637A108@qq.com
2026-08-12 14:42:57 +09:00
Michael Paquier
72a6dad1c9 Move index statistics into their own stats kind
This commit splits the relation and index stats data, where the index
data is now moved to a new kind called PGSTAT_KIND_INDEX.  A benefit of
this refactoring is a reduction of the shared memory required for each
index, the new PgStat_StatIdxEntry including only the fields required
for indexes.  This leads to less data flushed to disk on shutdown.
Another benefit is that the addition of new fields for relation-level
stats is easier to think about.  Note that indexes have no need for most
of the xact-level fields that relations care about, clarifying the role
of each counter for each relkind.

System views are updated to use the index-level functions.  Note this
split means a possible break for tools that had the idea to call the
SQL functions for relation stats (not documented), as now these would
return 0 when queried for an index.  These tools can use the new index
functions to achieve the same result.

As of this change, the pending statistics are still controlled by
PgStat_TableStatus for both relation and index kinds.  This is left as a
follow-up piece, this one being good enough on its own.  This commit is
focused on the changes required for the SQL interface, shared memory
management and the on-disk format.

Bump catalog version.
Bump PGSTAT_FILE_FORMAT_ID.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/f572abe7-a1bb-e13b-48c7-2ca150546822@gmail.com
2026-08-12 12:06:05 +09:00
Michael Paquier
feb15361b3 Fix unlink() error report in KeepFileRestoredFromArchive()
KeepFileRestoredFromArchive() has been using an incorrect WAL segment
name in the error report for an unlink() failure.

Even without 1200dfd60c, this was of consequence only on WIN32, where
we would miss to report a segment name suffixed by ".deleted%u".

Oversight in 60df192aea, for what looks like a copy-pasto to me.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwHSbJnUmWCuF-QNUsGYF=iSSuzLRx1z_dLfYFwfbTu4Cw@mail.gmail.com
2026-08-12 09:45:03 +09:00
Michael Paquier
afd63e0ad2 Improve GrantLockLocal() handling on out-of-memory errors
On the first LockAcquire for a lock tag, LockAcquireExtended() creates
a LOCALLOCK entry in the hash table LockMethodLocalHash, with lockOwners
set to NULL.  lockOwners is then allocated in TopMemoryContext.

If the allocation fails, the hash entry would persist with lockOwners
still NULL and maxLockOwners already set to 8.  A follow-up
LockAcquire() on the same entry would crash on a NULL pointer
dereference.

This commit adds an extra layer of safety for such a case, by
re-attempting MemoryContextAlloc() if a LOCALLOCK entry exists but its
lockOwners is still NULL due to a previous in-flight allocation failure.

This problem is unlikely going to show up in practice, so no backpatch
is done.

Author: Bryan Green <dbryan.green@gmail.com>
Author: Mark Dilger <mark.dilger@enterprisedb.com>
Discussion: https://postgr.es/m/c9a5eeb1-4d31-46e1-bb9e-33448a23a5d3@gmail.com
2026-08-12 09:09:58 +09:00
Tomas Vondra
931c9701f2 Change wal_compression=on to the first of zstd, lz4, pglz
Previously, wal_compression=on was an alias for pglz, with the
assumption that users could make an informed choice to pick a better
option. But in practice, users rarely got to that second step.

Many users don't want to be choosing algorithms - they just want WAL
compression, and expect that to work well. The configuration parameter
is set by administrators, who do not control the workload, and so are
not in a position to evaluate the options anyway. Some users may not
even realize there are other options, as previously "on" was the only
choice available.

This change maps "on" to non-pglz options, supported by the build. Both
lz4 and zstd are faster, with a comparable (or better) compression
ratio. We prefer zstd over lz4 - per our testing the better compression
ratio pays for the lower (de)compression speed.

Like for TOAST compression, the value depends on algorithms supported by
the PostgreSQL build, with lz4 and zstd being optional. But most builds
will have at least one of these external libraries. If neither zstd or
lz4 is supported, we fallback to pglz.

This only affects what "on" means. Users can still make the informed
choice and explicitly select a compression algorithm if it works better
for their system. The default value for "wal_compression" remains "off."

Initial proposal and patch by wenhui qiu, reviews and patch adjustments
by Christoph Berg. A number of other people participated in the
discussion. Benchmarks by me.

Backpatch to 19.

Author: wenhui qiu <qiuwenhuifx@gmail.com>
Reviewed-by: Christoph Berg <myon@debian.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAGjGUAL1b=Mwd1SCvLbo+fivEr9KDpFcu4jmqKCZXwT=6CiiGQ@mail.gmail.com
Backpatch-through: 19
2026-08-12 01:14:59 +02:00
Tom Lane
040932c311 Tweak allocation rule for tzload()'s "union local_storage" variable.
By default, allocate this via malloc, as we've been doing since commit
62c8421e8.  Commit aeb07c55f adopted upstream tzdb's default of
allocating it on the stack, but that still doesn't seem like a good
idea for the reasons given in 62c8421e8 (and now memorialized in a
comment, in hopes that we don't make the same mistake again).

However, under USE_VALGRIND, put it on the stack as upstream does.
This accidentally prevents a crash when Python 3.14 is used under
Valgrind.  The reasons for that are obscure, and it's most likely
not our bug, and even if we figured it out it'd be nice to have a fix
for buildfarm member skink now rather than after persuading the guilty
party to fix it.

In the normal non-USE_VALGRIND case, this has no effect on the logic
in released branches, and it reverts master to match them.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/f071e691-5930-4738-9dbd-43ed2da367fe@gmail.com
Backpatch-through: 14
2026-08-11 18:17:48 -04:00
Daniel Gustafsson
bc86dc738e libpq: remove unused field ssl_handshake_started from PGconn
The ssl_handshake_started field was added by d39a49c1e4 to allow
connection_failed() skip retrying with a different SSL negotiation
method, once the server had reported an error after the TLS handshake
had already started.  That logic was dropped by fb5718f35f, which
removed the ability to fall back from direct to negotiated SSL, and
with it the only consumer of the data in this field.  Fix by removing
the field.

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://postgr.es/m/CAJ7c6TPkHjVFERp1Fd-idMe=iRJnDX2Nzy_ZOkV=y4OLLgf89Q@mail.gmail.com
2026-08-11 21:53:59 +02:00
Peter Eisentraut
1d1d7b0e9c Use frontend logging API in fe_utils/string_utils.c
This simplifies error message printing a bit.

Author: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/c855d318-4545-4dc7-b466-2e24fbf64725%40eisentraut.org
2026-08-11 09:28:44 +02:00
Peter Eisentraut
c83a133f2b Make printTableAddCell/printTableAddHeader string argument const
These functions would sometimes overwrite the string argument they are
passed, namely via mbvalidate(), which removes invalid UTF-8
characters (or potentially analogously in other encodings, but that is
not implemented).  However, many callers are not expecting that.  In
many callers, the input value comes directly from libpq structures,
such as from PQgetvalue() or PQsslAttribute().  The latter actually
has a const char * return type, and that was cast away.  But even the
former is not expecting its return value to be modified.

Fix that by making these arguments const.  Internally, we add a
separate function that does only the checking part of mbvalidate().
Only if the validation returns a negative result, we make a copy and
run mbvalidate() on the copy.  printTableAddCell() already had
internal infrastructure for keeping track of what values needed to be
freed.  We add the same for printTableAddHeader().

In passing, also simplify the code a bit.  There were essentially
duplicate mechanisms for keeping track of the most recently added
cell (fields .cell and .cellsadded).  Make that consistent by using an
integer counter for everything.  That makes the code arguably easier
to read than with the "current pointer" approaches.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/c855d318-4545-4dc7-b466-2e24fbf64725%40eisentraut.org
2026-08-11 09:28:44 +02:00
Peter Eisentraut
59aec847fc Use frontend logging API in fe_utils/print.c
This simplifies error message printing a bit.  Also adjust the error
messages a bit for style, while we're here.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/c855d318-4545-4dc7-b466-2e24fbf64725%40eisentraut.org
2026-08-11 09:28:44 +02:00
Peter Eisentraut
0a92b9b762 Remove useless ENABLE_NLS conditionals
This already works even without those conditionals, since _() expands
to a no-op if NLS is disabled.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/c855d318-4545-4dc7-b466-2e24fbf64725%40eisentraut.org
2026-08-11 09:28:44 +02:00
Peter Eisentraut
370f3366c4 Remove useless/confusing const qualifiers
The const qualifiers removed here did not qualify what is being
pointed to, which is the normal use in function prototypes.  Instead,
they qualify the variable itself, so that it cannot be changed inside
the function.  That is itself not wrong, but it's not a normal style,
and it seems distracting here.

Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/c855d318-4545-4dc7-b466-2e24fbf64725%40eisentraut.org
2026-08-11 09:28:44 +02:00
David Rowley
d29d469bec Show estimated number of groups for Incremental Sort in EXPLAIN
Incremental Sort's costs heavily depend on the estimated number of input
groups with equal presorted key values.  Overestimations can cause the
planner to choose Incremental Sort over Sort when Sort would have
been a better choice.

Here, we add the planner's estimate to EXPLAIN to allow easier
understanding of why Incremental Sort has been chosen.

Author: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Reviewed-by: Enrique Sánchez <enriqueesanchz@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: solai v <solai.cdac@gmail.com>
Discussion: https://postgr.es/m/10682fef-3748-43f5-a932-7adcdd9bd2b8%40tantorlabs.com
2026-08-11 13:30:07 +12:00
Nathan Bossart
086f6f1760 psql: Don't do backquote expansion in \unrestrict.
This oversight in commit 71ea0d6795 allows a malicious server to
inject shell commands into plain-text dump output that are run at
restore time on the machine running psql.  To fix, interpret all
text after \unrestrict until the end of the line as its argument.

Reported-by: Lucas Velgus <velgusgus599@gmail.com>
Reported-by: Filip Janus <fjanus@redhat.com>
Reported-by: Daniel Bakker <daniel@jackds.nl>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Security: CVE-2026-18408
Backpatch-through: 14
2026-08-10 06:37:50 -07:00
Jacob Champion
49e7954148 pgcrypto: Add option to revert to prior decryption behavior
The previous commit raises an ERROR during PGP operations if OpenSSL
does not support the cipher in use. However, any existing messages
created with faulty encryption will no longer be accessible via
pgp_[sym|pub]_decrypt().

To help users out of this situation, add a new ignore-cipher-failure
option which reverts to the broken behavior during decryption only. A
faulty encryption wrapper, created by an OpenSSL configuration that does
not support the cipher, can then be stripped back off by that same
OpenSSL in order to safely reencrypt it. (Note that when OpenSSL does
support the cipher, corrupted messages will not be decrypted regardless
of the ignore-cipher-failure setting; this is unchanged.)

The new tests add a corrupted Blowfish message for both public- and
symmetric-key decryption, resulting in the following test matrix:

- Blowfish supported, default behavior:      fails to decrypt
- Blowfish supported, ignore-cipher-failure: fails to decrypt
- Blowfish unsupported, default behavior:    fails to load cipher
- Blowfish unsupported, ignore-cipher-failure: strips faulty encryption

The previous commit's change to the pubkey tests is expanded similarly:
correctly encrypted messages cannot be decrypted by an OpenSSL that does
not support the cipher, regardless of the option's setting, though the
failure mode will change.

Suggested-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Noah Misch <noah@leadboat.com>
Security: CVE-2026-14663
Backpatch-through: 14
2026-08-10 06:37:50 -07:00
Daniel Gustafsson
d0ecee6de9 Fix errorhandling for PGP encryption
PGP encryption was using px_cipher_encrypt without checking if any
error was returned.  When OpenSSL is running in FIPS mode, or when
the legacy provider hasn't been loaded, not all ciphers which are
supported by the PGP code are available and fail the init step in
px_cipher_encrypt.  Since the PGP encryption failed to notice this
it XORed the non-encrypted block with the plaintext, effectively
disabling the encryption.

This was found due to a report of PGP encryption not respecting
the pgcrypto.builtin_crypto_enabled flag and allowing Blowfish
and DES.  This however turned out to be a false positive, since
the PGP code only use ciphers from OpenSSL and not the built in
ciphers.

Bug: #19457
Reported-by: Shishir Sharma <ansh01072001@gmail.com>
Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>
Discussion: https://postgr.es/m/19457-4bab15c17aea36c7@postgresql.org
Security: CVE-2026-14663
Backpatch-through: 14
2026-08-10 06:37:50 -07:00
Michael Paquier
a16c31d39c Fix out-of-bound reads with ascii() for invalid multibyte characters
This commit addresses two defects in this SQL function, the code
assuming that:
- The user-supplied string was long enough to contain a character of the
length implied by the first byte.  It is possible to provide in input
data that was able to disclose a few bytes of server memory, allowing
out-of-bound reads.
- Specific bytes had values within the expected range, using a set of
assertions to validate them.  The assertions could be triggered on
invalid input.  These are replaced by tests and error reports.

Reported-by: Hcamael <baiyjrh@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Backpatch-through: 14
Security: CVE-2026-18024
2026-08-10 06:37:50 -07:00
Tom Lane
3045a25ba8 Teach psql to skip in-line COPY ... FROM STDIN data after a failure.
If the COPY command fails before sending PGRES_COPY_IN, psql did
not realize that it ought to consume any in-line data following
the command.  Failing to do so leads to trying to execute that
data as SQL commands, which in the best case is wrong and in the
worst case is a SQL-injection hazard.

To fix:

1. Extend psqlscan.l to recognize COPY ... FROM STDIN.  This can
be done with a pretty simple extension to the logic that already
recognizes nested BEGIN blocks within CREATE FUNCTION et al.
But unlike that case, we need to consider and count multiple COPY
commands within a single query string (separated by "\;").  The
fallout from that is that psql_scan_reset must now always be called
before starting a new query string.  (The comment for it that claimed
we didn't need that because "the scan state must be INITIAL" was
really obsolete already, since it has long reset more state besides
start_state.)

2. Teach handleCopyIn() to read and discard data when passed
NULL for "conn".

3. Add logic to SendQuery() to call handleCopyIn() that way
if the query string contained COPY ... FROM STDIN command(s)
that remain unaccounted-for at the end.

Now that we have this counting logic, we can also detect
if the backend sends an unexpected PGRES_COPY_IN message.
That should never happen, but perhaps a malicious server
could try to extract data that way.

A side-effect of doing this is that we have to adjust a number of test
scripts that thought they needn't write "\." after a COPY FROM STDIN
that they expect to fail.  On the whole this is an improvement, since
there's now a uniform rule "write \. after COPY FROM STDIN, whether
you expect it to work or not".  But it is an annoying amount of test
churn.

A loose end in this patch is that if it has to skip data, it assumes
that that data is text not binary.  It seems unduly difficult to
detect whether the COPY command requested binary (we could handle the
old-style COPY BINARY ... syntax, but not the new style with format
options).  In practice, copying in-line binary data is unsupported
anyway, because there's no way to write an end marker: the textual
terminator sequence "\n\\.\n" could appear in binary data and there's
no provision for escaping it, so neither psql nor the server look for
it when in binary mode.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 14
Security: CVE-2026-6464
2026-08-10 06:37:50 -07:00
Tom Lane
cf754f7414 Save/restore more lexer state when skipping text due to \if.
When we implemented \if ... \endif in psql, we arranged to
save/restore the lexer's parenthesis depth counter across any chunk
of input that we're ignoring.  At the time, that was sufficient,
because no other part of PsqlScanState could need to be restored to
its prior value.  However, commit e717a9a18 and follow-ons added
more state fields that ought to be restored to their prior values.
A problem would only be observed if someone tries to \if out a
portion of a CREATE FUNCTION/PROCEDURE command that is relevant to
BEGIN/END matching, which seems like a pretty unusual usage, so the
lack of field reports isn't surprising.  Nonetheless it's a bug.

To fix, replace the simple counter field in ConditionalStack
entries with a pointer to a struct defined by psqlscan_int.h.
(In the back branches, keep the old field and associated functions
to minimize the risk of API/ABI breakage, even though it seems
unlikely that any third-party code is using this.  Making the
new struct private to psqlscan-related code should prevent API/ABI
issues for future additions of this type.)

In itself this is only a minor bug fix, but it's prerequisite
infrastructure for the fix for CVE-2026-6464, which will add
another such field.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 14
Security: CVE-2026-6464
2026-08-10 06:37:50 -07:00
Nathan Bossart
ffca23839c Invalidate plan cache after role changes.
Role membership, role attribute, and database ownership changes may
impact the expected behavior of row-level security policies, but
currently the plan cache doesn't take notice.  To fix, register
syscache callbacks on pg_auth_members, pg_authid, and pg_database
that invalidate the role-dependent plans.  Changes to other
databases' pg_database rows are ignored.

Reported-by: Ilya Staroverov <i.staroverov@ftdata.ru>
Reported-by: Shinya Kato <shinya11.kato@gmail.com>
Author: Ilya Staroverov <i.staroverov@ftdata.ru>
Author: Shinya Kato <shinya11.kato@gmail.com>
Co-authored-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Security: CVE-2026-14666
Backpatch-through: 14
2026-08-10 06:37:50 -07:00
Nathan Bossart
53ed5ebd84 Check for USAGE privilege on the composite type in ALTER TABLE OF.
This omission allowed roles without USAGE on a type to create
tables that depend on it, which could prevent the owner from
changing the type later.

Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Security: CVE-2026-6470
Backpatch-through: 14
2026-08-10 06:37:50 -07:00
Nathan Bossart
4fac4c1085 Check for USAGE privilege on types used by stored expressions.
This omission allowed roles without USAGE on a type to create
stored expressions that depend on it, which could prevent the owner
from changing the type later.

The checks deliberately live in the command paths rather than the
dependency-recording routines.  Those routines also run whenever
the server re-derives an existing expression, and re-checking there
would break routine maintenance for an owner who has since lost
USAGE on a type its objects already reference.  (Checking in the
dependency-recording routines would also require additional
CommandCounterIncrement() calls to avoid spurious errors.)

The addition of a parameter to AlterDomainAddConstraint() breaks
ABI compatibility, but we are unaware of any impacted third-party
code.

Reported-by: Noah Misch <noah@leadboat.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Security: CVE-2026-6470
Backpatch-through: 14
2026-08-10 06:37:50 -07:00
Nathan Bossart
a9f6e768ac Check for USAGE privilege on the subtype in CREATE TYPE AS RANGE.
This omission allowed roles without USAGE on a type to create range
types that depend on it, which could prevent the owner from
changing the type later.

Reported-by: Jingzhou Fu <fuboat@outlook.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Security: CVE-2026-6470
Backpatch-through: 14
2026-08-10 06:37:49 -07:00
Nathan Bossart
918683d12d Avoid overflow in Levenshtein distance calculations.
levenshtein() and levenshtein_less_equal() let the caller specify
the insertion, deletion, and substitution costs, and
fuzzystrmatch's corresponding SQL functions accept any 32-bit
integer for each.  Since the distances are calculated with 32-bit
arithmetic, large costs can cause overflows, thereby producing
nonsensical results.  Certain inputs to levenshtein_less_equal()
can even cause out-of-bounds writes.  To fix, use 64-bit arithmetic
instead, and error whenever the final result won't fit in the
returned 32-bit integer.

We may want to teach these functions to reject negative costs, too,
but that didn't seem appropriate for a security fix, and therefore
it is left as a future exercise.

Reported-by: Ben Morris in collaboration with Claude and Anthropic Research
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Security: CVE-2026-15742
Backpatch-through: 14
2026-08-10 06:37:49 -07:00
Robert Haas
9e02e2e182 Cross-check the type of a portal running EXECUTE or FETCH.
When an EXECUTE or FETCH statement is executed, there are two portals:
an outer portal that is created for the EXECUTE or FETCH statement itself,
and an inner portal for the statement being executed on its behalf.
Before this commit, nothing checked that these two portals agreed on
the tuple descriptor of the rows being returned. This can be leveraged
to disclose server memory contents and achieve arbitrary code execution.

To prevent that, we can make use of an existing safety mechanism,
added by Tom Lane in commit 2f48ede080,
which allows a tuplestore DestReceiver to be informed of the tupleDesc
required by the caller, and which will cause an ERROR to occur if
that doesn't match the tupleDesc of what emerges from the executor
(modulo dropped columns, which aren't an issue in the case at hand).

Reported-by: Ben Morris in collaboration with Claude and Anthropic Research
Reported-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Security: CVE-2026-16239
2026-08-10 06:37:49 -07:00
Jacob Champion
226e49cbed Add an output_plugin_libraries GUC to bless trusted output plugins
REPLICATION users were not previously subject to restrictions on output
plugin paths, so they were able to bypass LOAD-time protections during
logical decoding. Unfortunately, adding the standard LOAD restrictions
now would retroactively require all third-party output plugins to be
installed under the $libdir/plugins directory. This would prevent the
use of dynamic_library_path, introduce a wire incompatibility for
clients, and require all plugin authors to check that their libraries
are safe for use by any unprivileged user; we want to avoid that.

Instead, introduce an output_plugin_libraries GUC so that DBAs can
specify the output plugins that are trusted for use in logical decoding.
For simplicity, superusers are subject to the restriction as well
(though they're free to modify the GUC at will during a session, so no
power is actually lost).

The default setting is 'pgoutput, test_decoding'. If other third-party
plugins are in use, DBAs will need to modify this parameter after they
update. Some pointers have been added to the documentation to assist
with this.

Author: Jacob Champion <jacob.champion@enterprisedb.com>
Reported-by: Vladimir Tokarev <vladimirelitokarev@gmail.com>
Reported-by: Yu Kunpeng <yu443940816@live.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Noah Misch <noah@leadboat.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 14
Security: CVE-2026-6471
2026-08-10 06:37:49 -07:00
Jacob Champion
20e9dcefdc Move SplitGUCList() to fe_utils
This is needed so that all versions of pg_upgrade that migrate logical
replication slots can parse the new output_plugin_libraries GUC.

Backpatch-through: 17
Security: CVE-2026-6471
2026-08-10 06:37:49 -07:00
Noah Misch
0fbf785b13 Empty search_path in amcheck.
A grantee of amcheck function EXECUTE privilege could execute arbitrary
functions as the owners of expression indexes that depend on the search
path.  An expression like (lower(col)) was not vulnerable, because
lower() is resolved at CREATE INDEX time.  However, an expression
calling an sql-language or plpgsql-language function often was
vulnerable, even if it used search_path only to find objects in
pg_catalog.  The amcheck documentation has been warning about data
disclosure after such a GRANT, not about function execution.

This might cause new amcheck errors when index expressions rely on a
broader search_path.  Such indexes have seen errors during auto-analyze
since CVE-2018-1058 commit 582edc369c, and
v17 amcheck always worked this way.  Hence, the risk is low.

Leave a comment on the one other sandbox entrance that doesn't empty
search_path.  In its case, the choice was valid.

Back-patch to v14 (all supported versions), but v17 was safe already.
Commit 2af07e2f74 (v17) unintentionally
blocked the attack, and commit d70b17636d
(v18) unintentionally removed that protection.  Hence, this adds to v17
just a test and a comment.  While emptying search_path became more
widespread in commit 2af07e2f74 (v17),
none of its other changes blocked an attack available in v16, even when
considering GRANT.  For example, brin_summarize_range() has had an owner
check that GRANT does not override.

Reported-by: 王跃林 <violin0613@tju.edu.cn>
Reported-by: Jacob Brazeal <jacob.brazeal@gmail.com>
Backpatch-through: 14
Security: CVE-2026-14673
2026-08-10 06:37:49 -07:00
Nathan Bossart
feb8b0182f Use value of scram_iterations in mock_scram_secret().
Presently, mock_scram_secret() always uses
SCRAM_SHA_256_DEFAULT_ITERATIONS, which poses an observable
response discrepancy hazard when scram_iterations is set to
something else.  To fix, use the value of the configuration
parameter instead, and document that unauthenticated users can
discover the existence of roles with passwords created with
different iteration counts.

Reported-by: Radim Marek <radim@boringsql.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Security: CVE-2026-14672
Backpatch-through: 16
2026-08-10 06:37:49 -07:00
Nathan Bossart
f9729b5078 Obstruct EXTRACT() field name deparse injection.
The parser accepts any string as an EXTRACT() field name, but
deparsing does not quote and escape it accordingly.  To fix, quote
and escape the field name during deparsing as needed.  It might be
a good idea to validate the field name during parsing and
deparsing, too, but that is left as a future exercise.

Reported-by: Ben Morris in collaboration with Claude and Anthropic Research
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Security: CVE-2026-15741
Backpatch-through: 14
2026-08-10 06:37:49 -07:00
Michael Paquier
57835938fa Fix multirange type handling in pg_restore_attribute_stats()
statatt_get_type() unconditionally converted multirange types to their
underlying range type.  This choice affected all the type information,
like atttypid, atttyptype and operators.

This made the bounds histogram work correctly (range type is required),
but it was wrong for all the other stat kinds.  MCV values for a
multirange column should be parsed as multirange arrays, not range
arrays.  It also made the TYPTYPE_MULTIRANGE check for the range stats
validation as dead code, since atttyptype was always TYPTYPE_RANGE
after the conversion due to the centralized statatt_get_type().

pg_restore_extended_stats() handles the same case correctly: it keeps
the original type and explicitly converts to the range type only at the
point where range_histogram_bounds is built.

The fix of this issue is simple: the multirange-to-range conversion
needs to be moved from the centralized statatt_get_type() up to where
attribute stats build their range_histogram_bounds, matching what is
done for extended statistics restore.

The regression tests for multiranges with attribute stats are extended
to cover this case.

Author: OpenAI Security Research Team
Backpatch-through: 18
Security: CVE-2026-16238
2026-08-10 06:37:49 -07:00
Michael Paquier
3bf185b4bb Reject GSSEncRequest after direct SSL connection
When a direct SSL connection was established, ProcessStartupPacket()
still accepted GSSEncRequest messages.  The GSSAPI negotiation would
then use raw writes and reads, bypassing the TLS encryption layer.
After the GSS encryption was established, the connection continued to
use TLS.  This could betray the HBA rules so as the backend does
protocol exchanges inconsistent with the connection policies in place,
with TLS taking priority over GSS in the backend.

The SSL negotiation path already guarded against attempts to request
SSL after a direct SSL request has been processed.  The GSS path is now
guarded the same way when receiving a startup packet.

Reported-by: p4p3r <kbfanta@naver.com>
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Jacob Champion <champion.p@gmail.com>
Backpatch-through: 17
Security: CVE-2026-14681
2026-08-10 06:37:49 -07:00
Michael Paquier
c7da85fec9 ecpg: Fix out-of-bound writes due to processing of invalid bytea data
ECPG assumes that any bytea data it receives from a backend starts with
'\x' as its first two bytes, but a check was missed to enforce that.  A
rogue server sending some garbage bytea data would be able to crash a
client, resulting in a client-side DoS, in the most common cases.

Reported-by: ylwangtju <ylwangtju@qq.com>
Backpatch-through: 14
Security: CVE-2026-16241
2026-08-10 06:37:49 -07:00
Heikki Linnakangas
776467301e Use palloc_array() in pltcl and plperl to avoid overflow
Some of these could overflow on 32-bit systems with the right input.
Convert all cases where we called palloc() with multiplication to fix
them. Not all of them were bugs, but it's better to be safe than
sorry.

Reported-by: Tulya Project, Team Dhiutsa, Bitecope Technologies Private Ltd
Backpatch-through: 14
Security: CVE-2026-14677
2026-08-10 06:37:49 -07:00
Heikki Linnakangas
66c2dbb204 Fix pg_trgm's picksplit function with all-true datums
The CACHESIGN.sign field is a BITVECP, not a TRGM, so you should not
use GETSIGN() on it. You don't get a compiler warning because the
GETSIGN() macro includes a cast. It resulted in a bogus read beyond
end of buffer, which would cause bad split decisions or a crash if
you're very unlucky.

Reported-by: Mehmet D. INCE <mehmet@mehmetince.net>
Backpatch-through: 14
Security: CVE-2026-14678
2026-08-10 06:37:48 -07:00
Álvaro Herrera
1e2795ddea pg_stat_statements: Fix buffer overflow with query normalization
Since commit 62d712ecfd, pg_stat_statements has been underestimating
the size of the result buffer possible for a normalized query, in cases
where the query includes many squashable lists, causing the normalized
query to write past the allocated area.

The allocated buffer size forgot to account for the comment appended in
a squashable list, "/*, ... */".  Instead of trying to track down
precisely how much space we need, fix by switch to using an expansible
StringInfo.  This not only fixes the bug, but it also makes the code
simpler to follow.

Author: Álvaro Herrera <alvherre@kurilemu.de>
Reported-by: Sajeeb Lohani with TrendAI Zero Day Initiative
Reported-by: Yuelin Wang <3020001251@tju.edu.cn>
Diagnosed-by: Michaël Paquier <michael@paquier.xyz>
Backpatch-through: 18
Security: CVE-2026-14676
Discussion: https://postgr.es/m/19528-7290dd7e6f7dcc22@postgresql.org
2026-08-10 06:37:48 -07:00
Masahiko Sawada
6713a6e04c Preserve the owner of extended statistics rebuilt by ALTER TABLE.
When ALTER TABLE ... ALTER COLUMN TYPE (or any subcommand that rebuilds
them) drops and re-creates the extended statistics objects depending on
the altered column, the re-created objects were owned by the role running
ALTER TABLE rather than by the original owner of the statistics.

Remember each object's owner before dropping it, and restore it on
re-creation.

CreateStatistics()'s signature changes and CreateStatsStmt gains a field,
but no known third-party code calls the former or constructs the latter.

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 14
Security: CVE-2026-6469
2026-08-10 06:37:48 -07:00
Tom Lane
1aa601b4f5 Return nulls honestly in aggregate "combine" functions.
numeric_combine() and several other state-combining functions for
aggregates cheated for the case of both inputs being NULL: they
returned a null pointer without bothering to mark it as a SQL NULL.
This was harmless in the expected usage where the result would be
passed to the same combine function or a related aggregate final
function.  But it's bad news from a security standpoint, because
now that value can be passed to an internal-accepting function
even if said function is strict.  While a previous patch prevented
such queries from being issued, it seems like good defense-in-depth
to expend the few additional lines of code needed to do this properly.
Comparable functions such as array_agg_combine() already do so.

Reported-by: Amy Burnett (OpenAI Codex Security)
Author: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 14
Security: CVE-2026-14680
2026-08-10 06:37:48 -07:00
Tom Lane
8f7e35b08a Reject calls from SQL to functions that take or return type internal.
Allowing that is a security hole, since there are many different
functions with different ideas of what their "internal" argument or
result is.  We already had a defense against the easy case of
"'foo'::internal", but that turns out to be insufficient.  Lock down
both function and operator syntax.  Also disallow attempts to cast to
or from type internal; those would mostly fail anyway, but we have
created some holes with features such as CoerceViaIO.

Reported-by: Amy Burnett (OpenAI Codex Security)
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Backpatch-through: 14
Security: CVE-2026-14680
2026-08-10 06:37:48 -07:00
Tom Lane
60e7329b9b Protect some fixed-size arrays that have FUNC_MAX_ARGS elements.
The maximum number of arguments allowed for an aggregate function
is FUNC_MAX_ARGS-1 (since the underlying transfn and/or finalfn
will be called with one more argument).  parse_func.c failed to
enforce this, allowing construction of calls that would try to
pass FUNC_MAX_ARGS+1 to the underlying functions, resulting in
a memory stomp in the executor.  Add correct checking there.

Since it's possible that a bad call has been stored in a view or
SQL function, also add checks in various aggregate-related and
window-function-related code that there are not more than
FUNC_MAX_ARGS arguments.  These will also protect us against the
possibility that we're trying to run a stored view that was made
by a server executable with different FUNC_MAX_ARGS.  (Arguably,
that scenario does not qualify as a security problem.  But let's
just tighten up all of this while we're here, rather than split
hairs over whether an overrun is reachable.)

Likewise check in compute_function_hashkey.  Here the hazard is
directly from a pg_proc row, but the scenario is the same.

PL/Tcl has a similar issue with a fixed-size string buffer.
Let's just replace that buffer with a Tcl_DString, removing the
whole issue and making the code look more like what's around it.

There are a lot of other FUNC_MAX_ARGS-sized arrays, but the rest
have nearby guards already, some with comments explicitly pointing
out the hazard of FUNC_MAX_ARGS changing.

I also used palloc_array() in a few related places in funcapi.c.
Those aren't live hazards AFAICS, but nearby code has been
palloc_array-ified already, so it seemed inconsistent to not use
it here.

Reported-by: Masahiko Sawada <sawada.mshk@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Backpatch-through: 14
Security: CVE-2026-14679
2026-08-10 06:37:48 -07:00
Tom Lane
13bb73aeb6 pg_dump: avoid assuming how long pg_proc.protrftypes can be.
The backend doesn't impose any particular limit on the length of this
array, and since there could be entries for both input and output
arguments, it's feasible for the length to exceed FUNC_MAX_ARGS
even without funny business.  This could lead to crashes or worse.

Moreover, pg_dump shouldn't rely on hard-coding FUNC_MAX_ARGS in the
first place: it has no business assuming that the backend it's dumping
from was compiled with the same value of FUNC_MAX_ARGS that it is.
So the stanza in dumpFunc() that allocates exactly FUNC_MAX_ARGS space
for the parsed OID array is fundamentally misguided.  And it's broken
in another way too: if there are exactly FUNC_MAX_ARGS OIDs, then
parseOidArray won't zero-fill any entries, allowing the subsequent
loop to run off the end of the array.  A crash seems unlikely in
this variant, but garbage output is certain.

To fix, redesign parseOidArray's API so that it does the
array-mallocing, which simplifies the callers anyway.  While we're
here, tighten and modernize it a bit; in particular, split it into
separate functions for OIDs and integers, as was foreseen long ago.
This lets us get rid of the confusing type-punning involved in
having IndxInfo.indkeys be declared as "Oid *" when it's really
potentially-signed ints.  Also, most of the callers expect an exact
number of array entries, so make it verify that not just check for
"too many".

I noted while testing that this dumpFunc() stanza isn't even reached
during check-world.  Add a function with transform to the regression
tests to rectify that.

Reported-by: Masahiko Sawada <sawada.mshk@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Backpatch-through: 14
Security: CVE-2026-19385
2026-08-10 06:37:48 -07:00
Tom Lane
7bd56f7a3b Replace fixed-size, too-short array with a palloc'd one.
MatchNamedCall's arggiven array was declared FUNC_MAX_ARGS long,
but we may actually use up to pronallargs elements, and that can
be more than FUNC_MAX_ARGS if the function has OUT arguments
(cf. ProcedureCreate).  Convert it to a palloc'd array.

Reported-by: Zheng Yu <zheng@depthfirst.com>
Reported-by: ylwangtju <ylwangtju@qq.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Backpatch-through: 14
Security: CVE-2026-14679
2026-08-10 06:37:48 -07:00
Tom Lane
8f0c3d2feb Be more wary about constant's datatype in scalarineqsel().
The special case here for estimating conditions involving a ctid
column failed to check that the RHS constant is of type tid.
While that'd always be true for the built-in operators that
reference this selectivity estimator, a maliciously constructed
operator could provide a user-controlled Datum value that would
get interpreted as an ItemPointer pointer.  That at least risks
SIGSEGV, and perhaps with a bit of sweat it could be used for
server memory disclosure.

Reported-by: Hcamael <baiyjrh@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 14
Security: CVE-2026-14668
2026-08-10 06:37:48 -07:00
Tom Lane
63cb15f40c Harden PL/Perl code against "tied" Perl arrays and hashes.
Tied arrays might report different sizes each time they are inspected.
To avoid generating a corrupt result array, fix plperl_array_to_datum()
to read av_len() of each input array only once.  If the input does
appear to get shorter, we'll fill nulls for the now-missing entries,
which seems fine.  Conversely, if it gets longer, we'll ignore the new
entries.

plperl_to_hstore() assumed that Perl's hv_iterinit() returns the
number of entries in the given Perl hash.  Usually that's true,
but per the Perl docs, "the return value is currently only meaningful
for hashes without tie magic".  That could potentially end in a memory
stomp.  We don't depend on that result value anywhere else, so don't
do so here either.

Reported-by: Hcamael <baiyjrh@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Andrew Dunstan <andrew@dunslane.net>
Backpatch-through: 14
Security: CVE-2026-14670
2026-08-10 06:37:48 -07:00
Masahiko Sawada
343aabf1d9 Fix potential buffer overrun in regexp match/split functions.
setup_regexp_matches() sizes the buffer used to convert matched
substrings back from pg_wchar form at the smaller of maxlen*eml and
the original string's byte length, on the assumption that such a
conversion cannot produce more bytes than the string it came
from. That assumption holds only for validly encoded input. But
pg_mb2wchar_with_len() silently accepts bytes that are invalid in the
database encoding, turning each such byte into one pg_wchar, and
converting that back can take more bytes than the input did. A string
made of such bytes therefore overruns the conversion buffer by up to
its own length, corrupting the following memory. regexp_match(),
regexp_matches(), regexp_split_to_table() and regexp_split_to_array()
are all affected.

Fix by dropping the tighter bound and always allocating maxlen*eml + 1
bytes.

Reported-by: Francesco Verardi <frevadiscor89@gmail.com>
Author: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Backpatch-through: 14
Security: CVE-2026-14664
2026-08-10 06:37:48 -07:00
Tom Lane
90649b6f84 Harden tsquery code against overflows.
The only overflow hazards I could find in tsquery construction
are in QTN2QT(), which builds a flat tsquery datum from the
QTNode tree representation used by tsquery_or, tsquery_rewrite,
and allied functions.  There are two:

1. It seems theoretically possible for the outputs of cntsize() to
overflow an int, so I widened them to size_t.  There's no hazard
certainly in tsquery_or and friends, but tsquery_rewrite could expand
the query tree by large multiples (by replacing many identical
subtrees with a large replacement tree), so in a 64-bit machine
with plenty of available memory it should be possible to build a
QTNode tree large enough to cause that.  If these counters did
overflow then we'd under-allocate the output tsquery and have a heap
overwrite problem.  size_t is sufficient, since it's counting the size
of a subset of an in-memory data structure.  We also have to fix the
TSQUERY_TOO_BIG() macro to not get confused if sumlen exceeds
MaxAllocSize.

2. fillQT() neglects to check that the new "distance" value for a
QI_VAL item fits into the available 20-bit field.  It's quite easy
to reach this, for example by tsquery_or'ing two near-megabyte-sized
tsquerys.  However, the result is only a corrupt tsquery that does
not represent the expected query, so perhaps this doesn't rise to
the level of a security bug.  Nonetheless it should be fixed.

Note: I followed the practice used in other tsquery code of checking
each distance value as it's assigned, which means that the last
operand string could extend past the MAXSTRPOS boundary.  This is a
bit different from the pattern used for tsvectors, which insist that
the total data length not exceed MAXSTRPOS and thereby avoid making
per-item checks.  Perhaps that should be harmonized sometime, but for
now it's okay for the two types to do this differently as long as
each one is self-consistent.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Backpatch-through: 14
Security: CVE-2026-14662
2026-08-10 06:37:47 -07:00