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

SERVER-32191 DocumentSourceSkip can overflow a long long when combining with adjacent skips #1225

Closed
wants to merge 11 commits into from

Conversation

KevinCybura
Copy link
Contributor

No description provided.

@cswanson310 cswanson310 self-assigned this Mar 16, 2018
@cswanson310 cswanson310 self-requested a review March 16, 2018 18:47
Copy link
Contributor

@cswanson310 cswanson310 left a comment

Choose a reason for hiding this comment

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

A couple small things

_nToSkip += nextSkip->getSkip();
container->erase(std::next(itr));
return itr;
if (std::numeric_limits<long long>::max() - _nToSkip - nextSkip->getSkip() >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment here describing that we want to avoid overflowing '_nToSkip'. This only works because we know the skips are non-negative, right? If _nToSkip were negative, it looks like we'd overflow.

@@ -65,5 +65,28 @@ TEST_F(DocumentSourceSkipTest, ShouldPropagatePauses) {
ASSERT_TRUE(skip->getNext().isEOF());
}

TEST_F(DocumentSourceSkipTest, SkipsChainedTogetherShouldNotOverFlowWhenOptimizing) {
// $skip should not optimize if overflow
Copy link
Contributor

Choose a reason for hiding this comment

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

'if overflow' doesn't really make sense. How about 'if combining the two values of skips would overflow a long long'. Ditto for the comment below.

TEST_F(DocumentSourceSkipTest, SkipsChainedTogetherShouldNotOverFlowWhenOptimizing) {
// $skip should not optimize if overflow
auto skipShort = DocumentSourceSkip::create(getExpCtx(), 1);
auto skipLong = DocumentSourceSkip::create(getExpCtx(), std::numeric_limits<long long>::max());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test to make sure that two $skips with std::numeric_limits<long long>::max() will not combine?

// $skip should not optimize if overflow
auto skipShort = DocumentSourceSkip::create(getExpCtx(), 1);
auto skipLong = DocumentSourceSkip::create(getExpCtx(), std::numeric_limits<long long>::max());
Pipeline::SourceContainer overFlowContainer;
Copy link
Contributor

Choose a reason for hiding this comment

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

total nitpick, but if overflow is one word, this should be 'overflowContainer' not 'overFlowContainer'.

_nToSkip += nextSkip->getSkip();
container->erase(std::next(itr));
return itr;
// '_nToSkip' can potentially overflow causing it to become negative and skip nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

All the changes look good here, thanks! Can you be sure to end all comments in periods: https://github.com/mongodb/mongo/wiki/Style-Guidelines#general-guidelines-for-commenting-code

Other than that this looks ready to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants