pgsql: pg_restore: Fix out-of-bounds accesses and path traversal.

From: Noah Misch <noah(at)leadboat(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pg_restore: Fix out-of-bounds accesses and path traversal.
Date: 2026-11-09 14:21:53
Message-ID: E1xQQFt-000000003Sr-48Xn@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pg_restore: Fix out-of-bounds accesses and path traversal.

pg_restore trusts the contents of the archives it reads, so a
maliciously crafted archive can cause out-of-bounds reads and
writes, or make pg_restore read files outside the archive
directory. This commit fixes the following issues:

* Dependency IDs read from the table of contents are used as array
subscripts without validation. To fix, reject any that is not a
positive integer.

* _getObjectDescription() and IssueACLPerBlob() can read past the
end of a string when an entry's DROP statement or large object
ACL has an unexpected form. To fix, check for the expected
prefix before moving past it.

* A crafted archive can cause the dump ID index to be built before
the table of contents has been read, in which case it is too
small for every later lookup. To fix, have the tar format reject
archives whose table of contents is not the first member.

* The directory format opens the files named in the archive
without inspecting them. To fix, reject names that contain a
directory separator and anything that isn't a regular file.

* A tar member length that does not fit in a pgoff_t can cause a
buffer overrun on 32-bit systems. To fix, reject such lengths.

* In the back-branches, buildTocEntryArrays() sizes the dump ID
index arrays with unchecked multiplication, which could overflow
size_t on 32-bit systems. To fix, use pg_malloc0_array().

A corrupt archive can still crash pg_restore in other ways, but
hardening against that didn't seem appropriate for a security fix,
and therefore it is left as a future exercise.

Reported-by: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Reported-by: Yonghwa Lee <underdog(at)theori(dot)io>
Reported-by: OpenSec <security(at)opensec(dot)in>
Reported-by: Ben Dixon <uk(dot)bendixon(at)gmail(dot)com>
Author: Dilip Kumar <dilipbalaut(at)gmail(dot)com>
Author: Yonghwa Lee <underdog(at)theori(dot)io>
Co-authored-by: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Reviewed-by: Noah Misch <noah(at)leadboat(dot)com>
Reviewed-by: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Security: CVE-2026-116314
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1f0ccd2f81fc78ff399c0295a0cdc36a64f13554
Author: Nathan Bossart <nathan(at)postgresql(dot)org>

Modified Files
--------------
src/bin/pg_dump/compress_io.c | 31 +++++++++++++++++++++++++++++++
src/bin/pg_dump/pg_backup_archiver.c | 25 ++++++++++++++++++++++---
src/bin/pg_dump/pg_backup_db.c | 8 +++++++-
src/bin/pg_dump/pg_backup_directory.c | 4 ++++
src/bin/pg_dump/pg_backup_tar.c | 20 ++++++++++++++++++++
5 files changed, 84 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Noah Misch 2026-11-09 14:21:54 pgsql: Fix use-after-free in pg_show_all_settings().
Previous Message Noah Misch 2026-11-09 14:21:52 pgsql: Avoid use-after-free hazards in re-entrant use of pltcl.