Skip to content

fix wiremessage oob in case of intmin #2076

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

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

Conversation

kobrineli
Copy link
Contributor

Couldn't attach GODRIVER task number, 'cause I get 403 forbidden trying to access the project page.

Summary

If length is in range from INT_MIN (i.e. -2147483648) to INT_MIN+3, length-4 < 0 check doesn't work as expected due to integer overflow.

Getting too small length leads to check pass and further out of bound access.

Adding an additional check for length being smaller than zero solves the issue.

@kobrineli kobrineli requested a review from a team as a code owner May 30, 2025 14:49
@kobrineli kobrineli requested a review from qingyang-hu May 30, 2025 14:49
@@ -406,7 +406,7 @@ func ReadMsgSectionDocumentSequence(src []byte) (identifier string, docs []bsonc
// sequence data.
func ReadMsgSectionRawDocumentSequence(src []byte) (identifier string, data []byte, rem []byte, ok bool) {
length, rem, ok := readi32(src)
if !ok || int(length) > len(src) || length-4 < 0 {
if !ok || int(length) > len(src) || length < 0 || length-4 < 0 {
Copy link
Member

@prestonvasquez prestonvasquez Jun 3, 2025

Choose a reason for hiding this comment

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

Suggest checking length < 4 instead of length < 0 || length-4 < 0 .

We should also add a test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, seems better

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.

2 participants