Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReadPacket and WritePacket payload length is a multiple #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

michaelyou
Copy link

MaxPayloadLen

#208

@siddontang
Copy link
Collaborator

PTAL @WangXiangUSTC

@WangXiangUSTC
Copy link
Contributor

@michaelyou could you please tell me how to reappear the bug? provide a test case

@michaelyou
Copy link
Author

michaelyou commented Dec 13, 2017

I think it's obvious. If the payload len is a multiply of MaxPayloadLen, the origin code will read once more, but there is nothing for reading. you will get an error in line 81. @WangXiangUSTC

@michaelyou
Copy link
Author

This bug may not happen in practical use(the probability is really small that the payload has a length of exactly MaxLengthlen),but it really exists logically.

@siddontang
Copy link
Collaborator

I think we should add a test now. Conn needs a net.Conn which we can construct a dummy one in the test with the length of payload equal MaxLength

@WangXiangUSTC
Copy link
Contributor

@michaelyou can you help us add a uint test of this function? otherwise it is difficult to check the correctness

@danieltahara
Copy link

Is this going to be merged? seems like a test like https://github.com/vitessio/vitess/pull/3935/files#diff-6a379d5bc6a249add52fb846b2ee9c3f would be sufficient

return errors.Errorf("invalid payload length %d", length)
}
// packet length [24 bit]
length := int(uint32(header[0]) | uint32(header[1])<<8 | uint32(header[2])<<16)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not checking length with max payload length here?

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.

5 participants