-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix integer overflow with max limit & batchsize #1810
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
Conversation
Eliminate unnecessary killCursors command when batchSize == limit can overflow if using Integer.MAX_VALUE for both. JAVA-5667 JAVA-5970
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an integer overflow issue in the FindOperation when both batchSize and limit are set to Integer.MAX_VALUE. The fix prevents incrementing the effective batch size when it would cause overflow, eliminating unnecessary killCursors commands.
- Adds overflow protection in FindOperation.getCommand() by checking that effectiveBatchSize is less than Integer.MAX_VALUE before incrementing
- Adds comprehensive unit tests to validate the behavior with various combinations of batchSize and limit values including edge cases with Integer.MAX_VALUE
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| FindOperation.java | Adds overflow check to prevent incrementing batch size when it equals Integer.MAX_VALUE |
| FindOperationUnitSpecification.groovy | Adds unit test covering batch size and limit combinations including Integer.MAX_VALUE edge cases |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
driver-core/src/test/unit/com/mongodb/internal/operation/FindOperationUnitSpecification.groovy
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Eliminate unnecessary killCursors command when batchSize == limit can overflow if using Integer.MAX_VALUE for both. JAVA-5667 JAVA-5970
Eliminate unnecessary killCursors command when batchSize == limit can overflow if using Integer.MAX_VALUE for both.
JAVA-5667
JAVA-5970