Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
rozza merged 2 commits into mongodb:main from rozza:JAVA-5970
Oct 1, 2025
Merged

Conversation

@rozza
Copy link
Member

@rozza rozza commented Sep 24, 2025

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
@rozza rozza requested a review from a team as a code owner September 24, 2025 10:24
@rozza rozza requested review from nhachicha and stIncMale and removed request for a team and nhachicha September 24, 2025 10:24
@rozza rozza requested review from Copilot and nhachicha and removed request for stIncMale September 30, 2025 14:28
Copy link
Contributor

Copilot AI left a 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.

@rozza rozza requested a review from nhachicha October 1, 2025 12:27
Copy link
Contributor

@nhachicha nhachicha left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@rozza rozza merged commit 567ca8e into mongodb:main Oct 1, 2025
52 of 56 checks passed
rozza added a commit to rozza/mongo-java-driver that referenced this pull request Oct 1, 2025
Eliminate unnecessary killCursors command when batchSize == limit
can overflow if using Integer.MAX_VALUE for both.
JAVA-5667
JAVA-5970
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments

@nhachicha nhachicha nhachicha approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /