Skip to content

Commit ef5a3b9

Browse files
committed
Loop when necessary in contrib/pgcrypto's pktreader_pull().
This fixes a scenario in which pgp_sym_decrypt() failed with "Wrong key or corrupt data" on messages whose length is 6 less than a power of 2. Per bug #11905 from Connor Penhale. Fix by Marko Tiikkaja, regression test case from Jeff Janes.
1 parent 39493e4 commit ef5a3b9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

contrib/pgcrypto/expected/pgp-decrypt.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,11 @@ a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
364364
(1 row)
365365

366366
-- expected: 7efefcab38467f7484d6fa43dc86cf5281bd78e2
367+
-- check BUG #11905, problem with messages 6 less than a power of 2.
368+
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
369+
?column?
370+
----------
371+
t
372+
(1 row)
373+
374+
-- expected: true

contrib/pgcrypto/pgp-decrypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pktreader_pull(void *priv, PullFilter *src, int len,
182182
if (pkt->type == PKT_CONTEXT)
183183
return pullf_read(src, len, data_p);
184184

185-
if (pkt->len == 0)
185+
while (pkt->len == 0)
186186
{
187187
/* this was last chunk in stream */
188188
if (pkt->type == PKT_NORMAL)

contrib/pgcrypto/sql/pgp-decrypt.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,7 @@ a3nsOzKTXUfS9VyaXo8IrncM6n7fdaXpwba/3tNsAhJG4lDv1k4g9v8Ix2dfv6Rs
264264
-----END PGP MESSAGE-----
265265
'), 'key', 'convert-crlf=1'), 'sha1'), 'hex');
266266
-- expected: 7efefcab38467f7484d6fa43dc86cf5281bd78e2
267+
268+
-- check BUG #11905, problem with messages 6 less than a power of 2.
269+
select pgp_sym_decrypt(pgp_sym_encrypt(repeat('x',65530),'1'),'1') = repeat('x',65530);
270+
-- expected: true

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy