Skip to content

Commit b3c630c

Browse files
committed
Fix incorrect value for "strategy" with deflateParams() in walmethods.c
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
1 parent 7fe55d5 commit b3c630c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/bin/pg_basebackup/walmethods.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
905905
return NULL;
906906

907907
/* Turn off compression for header */
908-
if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
908+
if (deflateParams(tar_data->zp, 0, Z_DEFAULT_STRATEGY) != Z_OK)
909909
{
910910
tar_set_error("could not change compression parameters");
911911
return NULL;
@@ -945,7 +945,8 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
945945
return NULL;
946946

947947
/* Re-enable compression for the rest of the file */
948-
if (deflateParams(tar_data->zp, tar_data->compression_level, 0) != Z_OK)
948+
if (deflateParams(tar_data->zp, tar_data->compression_level,
949+
Z_DEFAULT_STRATEGY) != Z_OK)
949950
{
950951
tar_set_error("could not change compression parameters");
951952
return NULL;
@@ -1164,7 +1165,7 @@ tar_close(Walfile f, WalCloseMethod method)
11641165
else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
11651166
{
11661167
/* Turn off compression */
1167-
if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
1168+
if (deflateParams(tar_data->zp, 0, Z_DEFAULT_STRATEGY) != Z_OK)
11681169
{
11691170
tar_set_error("could not change compression parameters");
11701171
return -1;
@@ -1176,7 +1177,8 @@ tar_close(Walfile f, WalCloseMethod method)
11761177
return -1;
11771178

11781179
/* Turn compression back on */
1179-
if (deflateParams(tar_data->zp, tar_data->compression_level, 0) != Z_OK)
1180+
if (deflateParams(tar_data->zp, tar_data->compression_level,
1181+
Z_DEFAULT_STRATEGY) != Z_OK)
11801182
{
11811183
tar_set_error("could not change compression parameters");
11821184
return -1;

0 commit comments

Comments
 (0)