fix(pg-protocol): copy the bytes a copyData message keeps out of the parser buffer - #3776
Open
nigrosimone wants to merge 1 commit into
Open
nigrosimone wants to merge 1 commit into
nigrosimone wants to merge 1 commit into
Conversation
Collaborator
|
It’s a risky API design, but I think it was intentional that parsed messages can contain buffers that reference the parser’s working buffer. Is anything in pg actually broken as a result? Then again, with binary mode being unimplemented, since |
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.
The parser hands
copyDatamessages achunkthat is a view into its own buffer (BufferReader.bytesusesslice). When the next socket chunk arrives and what is left of the previous one fits in front, the parser moves those bytes to the start of the same buffer, so a chunk delivered earlier changes under whoever kept it. AcopyDataof 64 bytes followed by acommandCompletecut at its last byte is enough: the chunk then starts withCOPY 1\0.pgitself ignorescopyData, but aSubmittablethat keeps the chunk, for example to push it into a stream, gets silently corrupted data. The MD5 salt goes through the same method.The fix returns a copy from
bytes().The added test parses that sequence in two chunks and checks the chunk is intact: it fails on master and passes here.