BUG #19891: pg_restore ignores an explicitly empty -F argument

Started by PG Bug reporting form17 days ago3 messagesbugs

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 19891
Logged by: Faye
Email address: imchifan@mail.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:

pg_restore treats an explicitly empty -F/--format argument as though the
option were absent and proceeds with archive-format auto-detection. With
empty input, I get an input-file error, while another invalid format is
rejected during option validation.

Because -F requires an archive format and accepts only c, d, or t, an
explicitly supplied empty value should be rejected as an unrecognized
archive format rather than enabling auto-detection.

How to repeat:

Run these commands with pg_restore on PATH:

```
pg_restore -f - -F '' </dev/null
pg_restore -f - -F garbage </dev/null
```

PostgreSQL 18.6 produces:

```
pg_restore: error: input file is too short (read 0, expected 5)
pg_restore: error: unrecognized archive format "garbage"; please specify
"c", "d", or "t"
```

The empty value should instead be rejected consistently with the other
invalid value, identifying the empty string as an unrecognized archive
format.

The issue was reproduced with pg_restore from PostgreSQL 18.6 (Debian
18.6-1.pgdg13+2) on Linux/amd64. The option handler records the format name
only when the argument is nonempty, so an explicitly empty argument remains
indistinguishable from an omitted -F option. This occurs when pg_restore is
invoked with an explicitly empty archive-format argument.

#2Raja Sai pranav
rajasaipranav0@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #19891: pg_restore ignores an explicitly empty -F argument

Hi,

I reproduced this on master (4a26e36f87) and attached a patch.

pg_restore only kept the -F value when it was not empty, so -F '' looked
the same as no -F at all and pg_restore went on to detect the format.
pg_dump already rejects an empty -F ("invalid output format "" specified").
The patch keeps the value always, so -F '' now fails the same way as -F
garbage:

pg_restore: error: unrecognized archive format ""; please specify "c", "d",
or "t"

The patch adds a test next to the existing garbage-format test in
src/bin/pg_dump/t/
https://www.google.com/url?q=http://001_basic.pl&source=gmail&ust=1795280332268000&sa=E.
The pg_dump test suites pass with the patch, and the new test fails without
it.

Regards,
Sai Pranav

On Fri, Nov 20, 2026 10:28 PM, PG Bug reporting form <noreply@postgresql.org>
wrote:

Show quoted text

The following bug has been logged on the website:

Bug reference: 19891
Logged by: Faye
Email address: imchifan@mail.com
PostgreSQL version: 18.6
Operating system: Linux/amd64
Description:

pg_restore treats an explicitly empty -F/--format argument as though the
option were absent and proceeds with archive-format auto-detection. With
empty input, I get an input-file error, while another invalid format is
rejected during option validation.

Because -F requires an archive format and accepts only c, d, or t, an
explicitly supplied empty value should be rejected as an unrecognized
archive format rather than enabling auto-detection.

How to repeat:

Run these commands with pg_restore on PATH:

```
pg_restore -f - -F '' </dev/null
pg_restore -f - -F garbage </dev/null
```

PostgreSQL 18.6 produces:

```
pg_restore: error: input file is too short (read 0, expected 5)
pg_restore: error: unrecognized archive format "garbage"; please specify
"c", "d", or "t"
```

The empty value should instead be rejected consistently with the other
invalid value, identifying the empty string as an unrecognized archive
format.

The issue was reproduced with pg_restore from PostgreSQL 18.6 (Debian
18.6-1.pgdg13+2) on Linux/amd64. The option handler records the format name
only when the argument is nonempty, so an explicitly empty argument remains
indistinguishable from an omitted -F option. This occurs when pg_restore is
invoked with an explicitly empty archive-format argument.

Attachments:

t258929_2
v1-0001-pg_restore-reject-an-empty-F-format-argument.patchtext/x-patch; charset=UTF-8; name=v1-0001-pg_restore-reject-an-empty-F-format-argument.patchDownload+6-3
#3Pierre Forstmann
pierre.forstmann@gmail.com
In reply to: Raja Sai pranav (#2)
Re: BUG #19891: pg_restore ignores an explicitly empty -F argument

Hello,

I  have also reproduced this on 18.7 version and on master
e87b024bfb8dd55e3049b1b6e6ab4e810cf1abc8.

I have rebuilt with your patch and run successfully: make
installcheck-world ?

I have also reviewed your code changes : LGTM.

I have set patch status to review.

Regards,

P.F.

Le 20/11/2026 à 17:58, Raja Sai pranav a écrit :

Show quoted text

Hi,

I reproduced this on master (4a26e36f87) and attached a patch.

pg_restore only kept the -F value when it was not empty, so -F ''
looked the same as no -F at all and pg_restore went on to detect the
format. pg_dump already rejects an empty -F ("invalid output format ""
specified"). The patch keeps the value always, so -F '' now fails the
same way as -F garbage:

pg_restore: error: unrecognized archive format ""; please specify "c",
"d", or "t"

The patch adds a test next to the existing garbage-format test in
src/bin/pg_dump/t/https://www.google.com/url?q=http://001_basic.pl&source=gmail&ust=1795280332268000&sa=E
<https://www.google.com/url?q=http://001_basic.pl&source=gmail&ust=1795280332268000&sa=E>.
The pg_dump test suites pass with the patch, and the new test fails
without it.

Regards,
Sai Pranav

On Fri, Nov 20, 2026 10:28 PM, PG Bug reporting form
<noreply@postgresql.org> wrote:

The following bug has been logged on the website:

Bug reference:      19891
Logged by:          Faye
Email address: imchifan@mail.com
PostgreSQL version: 18.6
Operating system:   Linux/amd64
Description:

pg_restore treats an explicitly empty -F/--format argument as
though the
option were absent and proceeds with archive-format
auto-detection. With
empty input, I get an input-file error, while another invalid
format is
rejected during option validation.

Because -F requires an archive format and accepts only c, d, or t, an
explicitly supplied empty value should be rejected as an unrecognized
archive format rather than enabling auto-detection.

How to repeat:

Run these commands with pg_restore on PATH:

```
pg_restore -f - -F '' </dev/null
pg_restore -f - -F garbage </dev/null
```

PostgreSQL 18.6 produces:

```
pg_restore: error: input file is too short (read 0, expected 5)
pg_restore: error: unrecognized archive format "garbage"; please
specify
"c", "d", or "t"
```

The empty value should instead be rejected consistently with the other
invalid value, identifying the empty string as an unrecognized archive
format.

The issue was reproduced with pg_restore from PostgreSQL 18.6 (Debian
18.6-1.pgdg13+2) on Linux/amd64. The option handler records the
format name
only when the argument is nonempty, so an explicitly empty
argument remains
indistinguishable from an omitted -F option. This occurs when
pg_restore is
invoked with an explicitly empty archive-format argument.