Skip to content

Conversation

@arp242
Copy link
Collaborator

@arp242 arp242 commented Dec 31, 2025

The Postgres wire protocol has certain fields that contain fixed-size integers, such as the 32-bit message length (see 1). This library does not check if values fit into these fixed-size fields before writing them to the buffer. This can lead to the truncation of the values being written, causing corrupted messages.

Example: If the message to be sent is 4^32 + 4 bytes long, the length cannot fit into the 4-byte length field. The value written to the buffer will be \x00\x00\x00\x04, which gets decoded to 4 by the Postgres database when it receives such a message. Therefore, the Postgres database will think the message has a length of 4 and will try to read the next message after those 4 bytes.

After such a malformed message, the client and the database have different understandings of where messages start and end. In the best case, this causes a connection abort due to a parsing error. In the worst case, this leads to the execution of malicious SQL statements that an attacker has injected into a large payload that ends up in an SQL query.

Continued from #1161, since I can't update that as it's a PR from the fork's master branch

Fixes #1153
Fixes #1161

The Postgres wire protocol has certain fields that contain fixed-size
integers, such as the 32-bit message length (see [1]). This library does
not check if values fit into these fixed-size fields before writing them
to the buffer. This can lead to the truncation of the values being
written, causing corrupted messages.

Example: If the message to be sent is 4^32 + 4 bytes long, the length
cannot fit into the 4-byte length field. The value written to the buffer
will be \x00\x00\x00\x04, which gets decoded to 4 by the Postgres
database when it receives such a message. Therefore, the Postgres
database will think the message has a length of 4 and will try to read
the next message after those 4 bytes.

After such a malformed message, the client and the database have
different understandings of where messages start and end. In the best
case, this causes a connection abort due to a parsing error. In the
worst case, this leads to the execution of malicious SQL statements that
an attacker has injected into a large payload that ends up in an SQL
query.

[1]: https://www.postgresql.org/docs/current/protocol-message-formats.html
@arp242 arp242 merged commit 872d42f into master Dec 31, 2025
21 checks passed
@arp242 arp242 deleted the 1161 branch January 1, 2026 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Looking for a security contact to disclose a vulnerability

3 participants