Skip to content

Commit adb371c

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 7dd9b46 commit adb371c

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
@@ -706,7 +706,7 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
706706
return NULL;
707707

708708
/* Turn off compression for header */
709-
if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
709+
if (deflateParams(tar_data->zp, 0, Z_DEFAULT_STRATEGY) != Z_OK)
710710
{
711711
tar_set_error("could not change compression parameters");
712712
return NULL;
@@ -744,7 +744,8 @@ tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_
744744
return NULL;
745745

746746
/* Re-enable compression for the rest of the file */
747-
if (deflateParams(tar_data->zp, tar_data->compression, 0) != Z_OK)
747+
if (deflateParams(tar_data->zp, tar_data->compression,
748+
Z_DEFAULT_STRATEGY) != Z_OK)
748749
{
749750
tar_set_error("could not change compression parameters");
750751
return NULL;
@@ -958,7 +959,7 @@ tar_close(Walfile f, WalCloseMethod method)
958959
else
959960
{
960961
/* Turn off compression */
961-
if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
962+
if (deflateParams(tar_data->zp, 0, Z_DEFAULT_STRATEGY) != Z_OK)
962963
{
963964
tar_set_error("could not change compression parameters");
964965
return -1;
@@ -969,7 +970,8 @@ tar_close(Walfile f, WalCloseMethod method)
969970
return -1;
970971

971972
/* Turn compression back on */
972-
if (deflateParams(tar_data->zp, tar_data->compression, 0) != Z_OK)
973+
if (deflateParams(tar_data->zp, tar_data->compression,
974+
Z_DEFAULT_STRATEGY) != Z_OK)
973975
{
974976
tar_set_error("could not change compression parameters");
975977
return -1;

0 commit comments

Comments
 (0)