BUG: pg_dump generates corrupted gzip file in Windows

From: Kuntal Ghosh <kuntalghosh(dot)2007(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: BUG: pg_dump generates corrupted gzip file in Windows
Date: 2017-03-24 05:58:28
Message-ID: CAGz5QCJPvbBjXAmJuGx1B_41yVCetAJhp7rtaDf7XQGWuB1GSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox
Lists: pgsql-hackers

In Windows, if one needs to take a dump in plain text format (this is
the default option, or can be specified using -Fp) with some level of
compression (-Z[0-9]), an output file has to
be specified. Otherwise, if the output is redirected to stdout, it'll
create a corrupted dump (cmd is set to ASCII mode, so it'll put
carriage returns in the file).

I'm referring the following part of pg_dump code:

* On Windows, we need to use binary mode to read/write non-text archive
* formats. Force stdin/stdout into binary mode if that is what we are
* using.
#ifdef WIN32
if (fmt != archNull &&
(AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0))
if (mode == archModeWrite)
setmode(fileno(stdout), O_BINARY);
setmode(fileno(stdin), O_BINARY);

For plain-text format, fmt is set to archNull. In that case, the
binary mode will not be forced(I think). To fix this, I've attached a
patch which adds one extra check in the 'if condition' to check the
compression level. PFA.

Thanks & Regards,
Kuntal Ghosh
EnterpriseDB: http://www.enterprisedb.com

Attachment Content-Type Size
0001-Fix-pg_dump-for-Windows-cmd.patch binary/octet-stream 1.2 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2017-03-24 06:01:46 Re: [pgsql-www] Small issue in online devel documentation build
Previous Message Ashutosh Bapat 2017-03-24 05:45:22 Re: create_unique_path and GEQO