Skip to content

Return an error instead of panicking on unknown response format code#1330

Draft
singhlovepreet9 wants to merge 1 commit into
lib:masterfrom
singhlovepreet9:fix-decode-unknown-format
Draft

Return an error instead of panicking on unknown response format code#1330
singhlovepreet9 wants to merge 1 commit into
lib:masterfrom
singhlovepreet9:fix-decode-unknown-format

Conversation

@singhlovepreet9

@singhlovepreet9 singhlovepreet9 commented Jul 11, 2026

Copy link
Copy Markdown

When dealing with a malformed or buggy server response (like in #1328), we can get an unknown format code that isn't text (0) or binary (1).

Previously, this would make it all the way down to decode() and trigger an unrecoverable panic("unreachable").

This PR changes parsePortalRowDescribe to check the format code straight off the wire. If it's invalid, we now return a proper error instead of letting it slip through and blow up the client later. This also addresses the previous review feedback to catch the error during column lookup rather than down in the decode loop.

Fixes #1328

@arp242

arp242 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

It should error on looking up the column.

Is this AI generated?

@singhlovepreet9 singhlovepreet9 force-pushed the fix-decode-unknown-format branch 2 times, most recently from 7d5f499 to de2642b Compare July 11, 2026 21:44
parsePortalRowDescribe (colFmts[i] = format(r.int16())) reads the format code
straight off the wire, so a malformed or buggy server response could crash
the client with an unrecoverable panic when it reaches decode() instead of
surfacing an error the caller can handle.

This change catches invalid format codes during parsing of the RowDescription
and returns an error immediately, preventing the invalid format from reaching
decode() later.

Fixes lib#1328
@singhlovepreet9 singhlovepreet9 force-pushed the fix-decode-unknown-format branch from de2642b to a504ebc Compare July 11, 2026 21:45
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.

Panic if RowDescription and/or DataRow doesn't include the requested column

2 participants