postgresql/src
Tom Lane bc30c704ad Harden astreamer tar parsing logic against archives it can't handle.
Previously, there was essentially no verification in this code that
the input is a tar file at all, let alone that it fits into the
subset of valid tar files that we can handle.  This was exposed by
the discovery that we couldn't handle files that FreeBSD's tar
makes, because it's fairly aggressive about converting sparse WAL
files into sparse tar entries.  To fix:

* Bail out if we find a pax extension header.  This covers the
sparse-file case, and also protects us against scenarios where
the pax header changes other file properties that we care about.
(Eventually we may extend the logic to actually handle such
headers, but that won't happen in time for v19.)

* Be more wary about tar file type codes in general: do not assume
that anything that's neither a directory nor a symlink must be a
regular file.  Instead, we just ignore entries that are none of the
three supported types.

* Apply pg_dump's isValidTarHeader to verify that a purported
header block is actually in tar format.  To make this possible,
move isValidTarHeader into src/port/tar.c, which is probably where
it should have been since that file was created.

I also took the opportunity to const-ify the arguments of
isValidTarHeader and tarChecksum, and to use symbols not hard-wired
constants inside tarChecksum.

Back-patch to v18 but not further.  Although this code exists inside
pg_basebackup in older branches, it's not really exposed in that
usage to tar files that weren't generated by our own code, so it
doesn't seem worth back-porting these changes across 3c9056981
and f80b09bac.  I did choose to include a back-patch of 5868372bb
into v18 though, to minimize cosmetic differences between these
two branches.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/3049460.1775067940@sss.pgh.pa.us>
Backpatch-through: 18
2026-04-02 12:20:36 -04:00
..
backend Remove redundant SetLatch() calls in interrupt handling functions 2026-04-02 23:55:30 +09:00
bin Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
common Make implementation of SASLprep compliant for ASCII characters 2026-03-24 08:29:23 +09:00
fe_utils Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
include Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
interfaces libpq: Allow developers to reimplement libpq-oauth 2026-03-31 11:47:26 -07:00
makefiles meson: Add {perl|python}_includespec to generated Makefile.global 2026-03-18 11:09:14 +01:00
pl Avoid including vacuum.h in tableam.h and heapam.h. 2026-03-31 12:43:52 -05:00
port Harden astreamer tar parsing logic against archives it can't handle. 2026-04-02 12:20:36 -04:00
template Switch the semaphore API on Solaris to unnamed POSIX. 2026-03-14 14:10:32 -04:00
test Use command_ok for pg_regress calls in 002_pg_upgrade and 027_stream_regress 2026-04-02 08:13:44 -04:00
timezone Use fallthrough attribute instead of comment 2026-02-19 08:51:12 +01:00
tools Add UPDATE/DELETE FOR PORTION OF 2026-04-01 19:06:03 +02:00
tutorial Force standard_conforming_strings to always be ON. 2026-01-21 15:08:38 -05:00
.gitignore
DEVELOPERS
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
Makefile.global.in Update Unicode data to Unicode 17.0.0 2026-03-20 08:42:50 +01:00
Makefile.shlib Restore AIX support. 2026-02-23 13:34:22 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
nls-global.mk Fix update-po for the PGXS case 2025-10-16 20:21:05 +02:00