On Windows, make pg_dump use binary mode for compressed plain text output.
authorTom Lane
Mon, 19 Jun 2017 15:02:45 +0000 (11:02 -0400)
committerTom Lane
Mon, 19 Jun 2017 15:03:07 +0000 (11:03 -0400)
The combination of -Z -Fp and output to stdout resulted in corrupted
output data, because we left stdout in text mode, resulting in newline
conversion being done on the compressed stream.  Switch stdout to binary
mode for this case, at the same place where we do it for non-text output
formats.

Report and patch by Kuntal Ghosh, tested by Ashutosh Sharma and Neha
Sharma.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/CAGz5QCJPvbBjXAmJuGx1B_41yVCetAJhp7rtaDf7XQGWuB1GSw@mail.gmail.com

src/bin/pg_dump/pg_backup_archiver.c

index 302882a5f7ce68bda998f45f96eaecc46337ab72..78e243c12c0b7db45a8d72d0671e411bc1e0c646 100644 (file)
@@ -2315,12 +2315,12 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
    AH->OF = stdout;
 
    /*
-    * 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.
+    * On Windows, we need to use binary mode to read/write non-text files,
+    * which include all archive formats as well as compressed plain text.
+    * Force stdin/stdout into binary mode if that is what we are using.
     */
 #ifdef WIN32
-   if (fmt != archNull &&
+   if ((fmt != archNull || compression != 0) &&
        (AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0))
    {
        if (mode == archModeWrite)