Thread: Re: libpq compression

Re: libpq compression

From
Konstantin Knizhnik
Date:

On 28.10.2020 17:57, Даниил Захлыстов wrote:
> Hi, thanks for the patch!
> I’ve made a quick review and found one issue.
> If the backend sends a CompressionAck message followed by some already 
> compressed message (for example, AuthenticationOk), then there is a 
> chance that pqReadData() will read both messages into the read buffer 
> at once. In this case, the CompressionAck message will be read 
> normally, but the client will fail to recognize the next message (for 
> example, AuthenticationOk) since it came in a compressed form but was 
> incorrectly read as a regular message. So the client would not be able 
> to recognize the second message and will crash.
> Example of a successful launch (added some debug output):
> usernamedt-osx: ~ usernamedt $ psql -d "host = x.x.x.x port = 6432 
> dbname = testdb user = testuser compression = 1"
> NUM_READ: 6 (pqReadData read CompressionAck (6 bytes) and nothing more)
> pqReadData RC: 1
> NUM_READ: 346
> pqReadData RC: 1
> psql (14devel)
> Type "help" for help.
> testdb => // OK
> Example of a failed launch:
> usernamedt-osx: ~ usernamedt $ psql -d "host = x.x.x.x port = 6432 
> dbname = testdb user = testuser compression = 1"
> NUM_READ: 24 (pqReadData read CompressionAck (6 bytes) and compressed 
> AuthenticationOk (18 bytes) came after it)
> pqReadData RC: 1
> psql: error: could not connect to server: expected authentication 
> request from server, but received x // FAIL

Thank you for reporting the problem.
Fix is attached.

-- 
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company


Attachment