]> granicus.if.org Git - postgresql/commitdiff
Restore use of zlib default compression in pg_dump directory mode.
authorAndrew Dunstan <andrew@dunslane.net>
Sat, 25 Jul 2015 21:14:36 +0000 (17:14 -0400)
committerAndrew Dunstan <andrew@dunslane.net>
Sat, 25 Jul 2015 21:15:32 +0000 (17:15 -0400)
This was broken by commit 0e7e355f27302b62af3e1add93853ccd45678443 and
friends, which ignored the fact that gzopen() will treat "-1" in the
mode argument as an invalid character, which it ignores, and a flag for
compression level 1. Now, when this value is encountered no compression
level flag is passed  to gzopen, leaving it to use the zlib default.

Also, enforce the documented allowed range for pg_dump's -Z option,
namely 0 .. 9, and remove some consequently dead code from
pg_backup_tar.c.

Problem reported by Marc Mamin.

Backpatch to 9.1, like the patch that introduced the bug.

src/bin/pg_dump/compress_io.c
src/bin/pg_dump/pg_backup_tar.c
src/bin/pg_dump/pg_dump.c

index 912fc2f695a15f0a8d61664e3ba163ab53ace033..6e1469bb75fce25bd41d53a1b165bf79f3f236bf 100644 (file)
@@ -547,11 +547,21 @@ cfopen(const char *path, const char *mode, int compression)
        if (compression != 0)
        {
 #ifdef HAVE_LIBZ
-               char            mode_compression[32];
+               if (compression != Z_DEFAULT_COMPRESSION)
+               {
+                       /* user has specified a compression level, so tell zlib to use it */
+                       char            mode_compression[32];
+
+                       snprintf(mode_compression, sizeof(mode_compression), "%s%d",
+                                        mode, compression);
+                       fp->compressedfp = gzopen(path, mode_compression);
+               }
+               else
+               {
+                       /* don't specify a level, just use the zlib default */
+                       fp->compressedfp = gzopen(path, mode);
+               }
 
-               snprintf(mode_compression, sizeof(mode_compression), "%s%d",
-                                mode, compression);
-               fp->compressedfp = gzopen(path, mode_compression);
                fp->uncompressedfp = NULL;
                if (fp->compressedfp == NULL)
                {
index 309b4b53dbc0546c8f4a55cba85324b3d3d7fd84..8730c5ea914c29765a5e969eb1c93053140acb0f 100644 (file)
@@ -208,13 +208,6 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
 
                ctx->hasSeek = checkSeek(ctx->tarFH);
 
-               if (AH->compression < 0 || AH->compression > 9)
-                       AH->compression = Z_DEFAULT_COMPRESSION;
-
-               /* Don't compress into tar files unless asked to do so */
-               if (AH->compression == Z_DEFAULT_COMPRESSION)
-                       AH->compression = 0;
-
                /*
                 * We don't support compression because reading the files back is not
                 * possible since gzdopen uses buffered IO which totally screws file
index 6664cee3b4cd8bf968f5588ca525ed2180025843..0b5262a8a1a7d0919cfdbecd09751abff438d351 100644 (file)
@@ -485,6 +485,11 @@ main(int argc, char **argv)
 
                        case 'Z':                       /* Compression Level */
                                compressLevel = atoi(optarg);
+                               if (compressLevel < 0 || compressLevel > 9)
+                               {
+                                       write_msg(NULL, "compression level must be in range 0..9\n");
+                                       exit_nicely(1);
+                               }
                                break;
 
                        case 0: