postgresql/src/bin/pg_dump
Tom Lane 2c9b857afb Fix pg_restore's misdesigned code for detecting archive file format.
Despite the clear comments pointing out that the duplicative code
segments in ReadHead() and _discoverArchiveFormat() needed to be
in sync, they were not: the latter did not bother to apply any of
the sanity checks in the former.  We'd missed noticing this partly
because none of those checks would fail in scenarios we customarily
test, and partly because the oversight would be masked if both
segments execute, which they would in cases other than needing to
autodetect the format of a non-seekable stdin source.  However,
in a case meeting all these requirements --- for example, trying
to read a newer-than-supported archive format from non-seekable
stdin --- pg_restore missed applying the version check and would
likely dump core or otherwise misbehave.

The whole thing is silly anyway, because there seems little reason
to duplicate the logic beyond the one-line verification that the
file starts with "PGDMP".  There seems to have been an undocumented
assumption that multiple major formats (major enough to require
separate reader modules) would nonetheless share the first half-dozen
fields of the custom-format header.  This seems unlikely, so let's
fix it by just nuking the duplicate logic in _discoverArchiveFormat().

Also get rid of the pointless attempt to seek back to the start of
the file after successful autodetection.  That wastes cycles and
it means we have four behaviors to verify not two.

Per bug #16951 from Sergey Koposov.  This has been broken for
decades, so back-patch to all supported versions.

Discussion: https://postgr.es/m/16951-a4dd68cf0de23048@postgresql.org
2021-04-01 13:34:16 -04:00
..
po Translation updates 2020-11-09 12:47:52 +01:00
t Solve cross-version-upgrade testing problem induced by 1fb57af92. 2019-02-09 21:02:06 -05:00
.gitignore Clean up after pg_dump test runs. 2016-05-06 22:28:01 -04:00
common.c Avoid trying to restore table ACLs and per-column ACLs in parallel. 2020-07-11 13:36:51 -04:00
compress_io.c Fix pg_dump's errno checking for zlib I/O 2017-08-02 18:26:58 -04:00
compress_io.h Fix pg_dump's errno checking for zlib I/O 2017-08-02 18:26:58 -04:00
dumputils.c Fix pg_dump for GRANT OPTION among initial privileges. 2021-01-16 12:21:39 -08:00
dumputils.h Further fixes for quoted-list GUC values in pg_dump and ruleutils.c. 2018-07-31 13:00:08 -04:00
Makefile Prevent accidental linking of system-supplied copies of libpq.so etc. 2018-07-09 17:23:31 -04:00
nls.mk Translation updates 2018-08-06 19:44:29 +02:00
parallel.c In libpq for Windows, call WSAStartup once and WSACleanup not at all. 2020-10-19 11:23:52 -04:00
parallel.h Fix parallel pg_dump/pg_restore for failure to create worker processes. 2020-01-31 14:41:49 -05:00
pg_backup.h Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:21 -05:00
pg_backup_archiver.c Fix pg_restore's misdesigned code for detecting archive file format. 2021-04-01 13:34:16 -04:00
pg_backup_archiver.h Fix pg_restore's misdesigned code for detecting archive file format. 2021-04-01 13:34:16 -04:00
pg_backup_custom.c Fix typos in comments. 2017-02-06 11:34:15 +02:00
pg_backup_db.c Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:21 -05:00
pg_backup_db.h Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:21 -05:00
pg_backup_directory.c Ensure write failure reports no-disk-space 2020-06-19 16:46:07 -04:00
pg_backup_null.c Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. 2016-03-24 15:55:57 -04:00
pg_backup_tar.c Fix pg_restore's misdesigned code for detecting archive file format. 2021-04-01 13:34:16 -04:00
pg_backup_tar.h Fix tar files emitted by pg_dump and pg_basebackup to be POSIX conformant. 2012-09-28 15:19:15 -04:00
pg_backup_utils.c Clean up thread management in parallel pg_dump for Windows. 2016-05-27 12:02:09 -04:00
pg_backup_utils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_dump.c Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:21 -05:00
pg_dump.h Add pg_dump support for ALTER obj DEPENDS ON EXTENSION 2020-03-11 16:54:54 -03:00
pg_dump_sort.c Fix pg_dump/pg_restore to restore event triggers later. 2020-03-09 14:58:11 -04:00
pg_dumpall.c Report the true database name on connection errors 2021-01-26 16:42:13 -03:00
pg_restore.c Fix handling of -d "connection string" in pg_dump/pg_restore. 2020-09-24 18:19:39 -04:00