Skip to content

pgrepr: Fix i16 overflow panic decoding binary numeric#37070

Merged
ggevay merged 1 commit into
MaterializeInc:mainfrom
ggevay:fix-numeric-from-sql-i16-overflow
Jun 16, 2026
Merged

pgrepr: Fix i16 overflow panic decoding binary numeric#37070
ggevay merged 1 commit into
MaterializeInc:mainfrom
ggevay:fix-numeric-from-sql-i16-overflow

Conversation

@ggevay

@ggevay ggevay commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes SQL-385

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. An 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.

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>
@ggevay ggevay requested a review from a team as a code owner June 16, 2026 12:08
@ggevay ggevay added the A-ADAPTER Topics related to the ADAPTER layer label Jun 16, 2026
@ggevay ggevay merged commit 0c6fd21 into MaterializeInc:main Jun 16, 2026
119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ADAPTER Topics related to the ADAPTER layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants