Fix incorrect value for "strategy" with deflateParams() in walmethods.c
authorMichael Paquier <[email protected]>
Wed, 14 Sep 2022 05:52:20 +0000 (14:52 +0900)
committerMichael Paquier <[email protected]>
Wed, 14 Sep 2022 05:52:20 +0000 (14:52 +0900)
The zlib documentation mentions the values supported for the compression
strategy, but this code has been using a hardcoded value of 0 rather
than Z_DEFAULT_STRATEGY.  This commit adjusts the code to use
Z_DEFAULT_STRATEGY.

Backpatch down to where this code has been added to ease the backport of
any future patch touching this area.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/1400032.1662217889@sss.pgh.pa.us
Backpatch-through: 10

src/bin/pg_basebackup/walmethods.c

index e90aa0ba377d33e24dd43919c6cc30ecd9527529..4d4bc63fbe71e47fb4681cf3d7784582aac27219 100644 (file)
@@ -904,7 +904,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
                        return NULL;
 
                /* Turn off compression for header */
-               if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
+               if (deflateParams(tar_data->zp, 0, Z_DEFAULT_STRATEGY) != Z_OK)
                {
                        tar_set_error("could not change compression parameters");
                        return NULL;
@@ -944,7 +944,8 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
                        return NULL;
 
                /* Re-enable compression for the rest of the file */
-               if (deflateParams(tar_data->zp, tar_data->compression_level, 0) != Z_OK)
+               if (deflateParams(tar_data->zp, tar_data->compression_level,
+                                                 Z_DEFAULT_STRATEGY) != Z_OK)
                {
                        tar_set_error("could not change compression parameters");
                        return NULL;
@@ -1162,7 +1163,7 @@ tar_close(Walfile f, WalCloseMethod method)
        else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
        {
                /* Turn off compression */
-               if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
+               if (deflateParams(tar_data->zp, 0, Z_DEFAULT_STRATEGY) != Z_OK)
                {
                        tar_set_error("could not change compression parameters");
                        return -1;
@@ -1174,7 +1175,8 @@ tar_close(Walfile f, WalCloseMethod method)
                        return -1;
 
                /* Turn compression back on */
-               if (deflateParams(tar_data->zp, tar_data->compression_level, 0) != Z_OK)
+               if (deflateParams(tar_data->zp, tar_data->compression_level,
+                                                 Z_DEFAULT_STRATEGY) != Z_OK)
                {
                        tar_set_error("could not change compression parameters");
                        return -1;