pgrepr: Fix i16 overflow panic decoding binary numeric#37070
Merged
ggevay merged 1 commit intoJun 16, 2026
Conversation
The `numeric` binary wire header (ndigits/weight/sign/dscale) is read as i16 straight from the client's Bind parameter, and the scale was computed in i16: `(units - weight - 1) * 4`. A user-controlled `weight` of i16::MIN overflows this, panicking (and, with overflow-checks, aborting) the pgwire connection task -- a remote, post-auth, single-message DoS. Compute the scale in i32 (the i16 wire fields cannot overflow it) and explicitly reject headers whose implied scale exceeds the decode context's precision, returning a clean INVALID_PARAMETER_VALUE instead of panicking. Adds a pgtest regression test (numeric-binary-overflow.pt) plus param_formats/binary_values support in the pgtest harness to drive binary-format parameters. SQL-385 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
aljoscha
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes SQL-385
The
numericbinary wire header (ndigits/weight/sign/dscale) is read as i16 straight from the client's Bind parameter, and the scale was computed in i16:(units - weight - 1) * 4. An user-controlledweightof i16::MIN overflows this, panicking (and, with overflow-checks, aborting) the pgwire connection task -- a remote, post-auth, single-message DoS.Compute the scale in i32 (the i16 wire fields cannot overflow it) and explicitly reject headers whose implied scale exceeds the decode context's precision, returning a clean INVALID_PARAMETER_VALUE instead of panicking.
Adds a pgtest regression test (numeric-binary-overflow.pt) plus param_formats/binary_values support in the pgtest harness to drive binary-format parameters.