Skip to content

fix(pg): reject queries exceeding parameter limit - #3829

Open
ritiksahni wants to merge 1 commit into
brianc:masterfrom
ritiksahni:fix/parameter-count-limit
Open

ritiksahni wants to merge 1 commit into
brianc:masterfrom
ritiksahni:fix/parameter-count-limit

Conversation

@ritiksahni

Copy link
Copy Markdown

PostgreSQL supports at most 65,535 parameters in a query. pg currently accepts more than that, causing the parameter count to wrap around to a smaller number before it is sent. PostgreSQL then receives a malformed request and returns a confusing error.

This change rejects oversized queries before sending anything to PostgreSQL. The connection remains usable, and other queries in a pipeline continue normally. The valid maximum of 65,535 parameters is still supported.

The fix covers regular queries, cursors, query streams, and the low-level protocol serializer. Tests verify both sides of the limit and connection reuse against PostgreSQL 18.

Native mode already gets the same validation from libpq and does not need to change.

Fixes #2579.

Reject more than 65535 parameters before writing protocol messages. Preserve the maximum valid count and add coverage for client, pipeline, cursor, and serializer paths.
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.

Queries with more than 32k parameters are allowed

1 participant