Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 84bf6ec

Browse files
committed
Restore use of zlib default compression in pg_dump directory mode.
This was broken by commit 0e7e355 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.
1 parent 6ae9a02 commit 84bf6ec

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/bin/pg_dump/compress_io.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,21 @@ cfopen(const char *path, const char *mode, int compression)
560560
if (compression != 0)
561561
{
562562
#ifdef HAVE_LIBZ
563-
char mode_compression[32];
563+
if (compression != Z_DEFAULT_COMPRESSION)
564+
{
565+
/* user has specified a compression level, so tell zlib to use it */
566+
char mode_compression[32];
567+
568+
snprintf(mode_compression, sizeof(mode_compression), "%s%d",
569+
mode, compression);
570+
fp->compressedfp = gzopen(path, mode_compression);
571+
}
572+
else
573+
{
574+
/* don't specify a level, just use the zlib default */
575+
fp->compressedfp = gzopen(path, mode);
576+
}
564577

565-
snprintf(mode_compression, sizeof(mode_compression), "%s%d",
566-
mode, compression);
567-
fp->compressedfp = gzopen(path, mode_compression);
568578
fp->uncompressedfp = NULL;
569579
if (fp->compressedfp == NULL)
570580
{

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
209209

210210
ctx->hasSeek = checkSeek(ctx->tarFH);
211211

212-
if (AH->compression < 0 || AH->compression > 9)
213-
AH->compression = Z_DEFAULT_COMPRESSION;
214-
215-
/* Don't compress into tar files unless asked to do so */
216-
if (AH->compression == Z_DEFAULT_COMPRESSION)
217-
AH->compression = 0;
218-
219212
/*
220213
* We don't support compression because reading the files back is not
221214
* possible since gzdopen uses buffered IO which totally screws file

src/bin/pg_dump/pg_dump.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ main(int argc, char **argv)
514514

515515
case 'Z': /* Compression Level */
516516
compressLevel = atoi(optarg);
517+
if (compressLevel < 0 || compressLevel > 9)
518+
{
519+
write_msg(NULL, "compression level must be in range 0..9\n");
520+
exit_nicely(1);
521+
}
517522
break;
518523

519524
case 0:

0 commit comments

Comments
 (0)