Repository navigation
pg-protocol: stop parseErrorMessage looping on an empty error or notice body - #3874
Closed
aaronjmars wants to merge 1 commit into
Closed
aaronjmars wants to merge 1 commit into
aaronjmars wants to merge 1 commit into
Conversation
…ce body An ErrorResponse or NoticeResponse with length 4 has no body. The first reader.string(1) then reads past the frame, and once past the end of the buffer it returns '' forever, so the field loop never ends. Clamp error and notice reads to the declared body and return a DatabaseError when the field list has no terminator.
Collaborator
|
incomplete/misleading title → bad test. bad implementation. not a fan of undisclosed AI-generated text and code. just open an issue. |
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.
An ErrorResponse (
E) or NoticeResponse (N) frame with length 4 has no body.parseErrorMessagereads a field type withreader.string(1)and loops until it sees\0. With an empty body that first read is already past the frame: it either consumes the next message, or, at the end of the buffer, keeps returning''so the loop never ends and the parse call never returns. For example,new Parser().parse(Buffer.from([0x45, 0, 0, 0, 4]), cb)hangs.This is a different loop from the one fixed in #3691. That PR made
cstring()stop on any falsy byte; the outerwhile (fieldType !== '\0')loop inparseErrorMessagestill spins whenreader.string(1)returns''.Changes:
EandNmessages, so a short frame cannot read into the next message.DatabaseErrorif the field list ends without its terminator, instead of looping.Normal PostgreSQL servers never send this frame, so behavior for real error and notice messages is unchanged.
Tests: added cases in
inbound-parser.test.tsfor an emptyEandNframe, both alone and followed byReadyForQuery. Without the fix the alone case hangs; with it all 82 pg-protocol tests pass.