Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ccf964a

Browse filesBrowse files
committed
Fix ancient violation of zlib's API spec.
contrib/pgcrypto mishandled the case where deflate() does not consume all of the offered input on the first try. It reset the next_in pointer to the start of the input instead of leaving it alone, causing the wrong data to be fed to the next deflate() call. This has been broken since pgcrypto was committed. The reason for the lack of complaints seems to be that it's fairly hard to get stock zlib to not consume all the input, so long as the output buffer is big enough (which it normally would be in pgcrypto's usage; AFAICT the input is always going to be packetized into packets no larger than ZIP_OUT_BUF). However, IBM's zlibNX implementation for AIX evidently will do it in some cases. I did not add a test case for this, because I couldn't find one that would fail with stock zlib. When we put back the test case for bug #16476, that will cover the zlibNX situation well enough. While here, write deflate()'s second argument as Z_NO_FLUSH per its API spec, instead of hard-wiring the value zero. Per buildfarm results and subsequent investigation. Discussion: https://postgr.es/m/16476-692ef7b84e5fb893@postgresql.org
1 parent edfc086 commit ccf964a
Copy full SHA for ccf964a

File tree

Expand file treeCollapse file tree

1 file changed

+5
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-5
lines changed

‎contrib/pgcrypto/pgp-compress.c

Copy file name to clipboardExpand all lines: contrib/pgcrypto/pgp-compress.c
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ compress_process(PushFilter *next, void *priv, const uint8 *data, int len)
115115
/*
116116
* process data
117117
*/
118-
while (len > 0)
118+
st->stream.next_in = (void *) data;
119+
st->stream.avail_in = len;
120+
while (st->stream.avail_in > 0)
119121
{
120-
st->stream.next_in = (void *) data;
121-
st->stream.avail_in = len;
122122
st->stream.next_out = st->buf;
123123
st->stream.avail_out = st->buf_len;
124-
res = deflate(&st->stream, 0);
124+
res = deflate(&st->stream, Z_NO_FLUSH);
125125
if (res != Z_OK)
126126
return PXE_PGP_COMPRESSION_ERROR;
127127

@@ -132,7 +132,6 @@ compress_process(PushFilter *next, void *priv, const uint8 *data, int len)
132132
if (res < 0)
133133
return res;
134134
}
135-
len = st->stream.avail_in;
136135
}
137136

138137
return 0;
@@ -155,6 +154,7 @@ compress_flush(PushFilter *next, void *priv)
155154
zres = deflate(&st->stream, Z_FINISH);
156155
if (zres != Z_STREAM_END && zres != Z_OK)
157156
return PXE_PGP_COMPRESSION_ERROR;
157+
158158
n_out = st->buf_len - st->stream.avail_out;
159159
if (n_out > 0)
160160
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.