Fix corner case with PGP decompression in pgcrypto
authorMichael Paquier <[email protected]>
Wed, 22 Jul 2020 05:53:22 +0000 (14:53 +0900)
committerMichael Paquier <[email protected]>
Wed, 22 Jul 2020 05:53:22 +0000 (14:53 +0900)
commite0cb8282d61411300c593e18237e50f3d26a825e
tree231cf1851ced902f23b5a7a5c3dc6432d90eac5e
parent5cd4954bb6edc5e50ade3f38ebbbf869c6313534
Fix corner case with PGP decompression in pgcrypto

A compressed stream may end with an empty packet, and PGP decompression
finished before reading this empty packet in the remaining stream.  This
caused a failure in pgcrypto, handling this case as corrupted data.
This commit makes sure to consume such extra data, avoiding a failure
when decompression the entire stream.  This corner case was reproducible
with a data length of 16kB, and existed since its introduction in
e94dd6a.  A cheap regression test is added to cover this case.

Thanks to Jeff Janes for the extra investigation.

Reported-by: Frank Gagnepain
Author: Kyotaro Horiguchi, Michael Paquier
Discussion: https://postgr.es/m/16476-692ef7b84e5fb893@postgresql.org
Backpatch-through: 9.5
contrib/pgcrypto/expected/pgp-compression.out
contrib/pgcrypto/pgp-compress.c
contrib/pgcrypto/sql/pgp-compression.sql