-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 overflow bug in SortingNumericDocValues #70154
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
server/src/test/java/org/elasticsearch/index/fielddata/SortingNumericDocValuesTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.fielddata; | ||
|
||
import org.apache.lucene.util.ArrayUtil; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.function.LongConsumer; | ||
|
||
public class SortingNumericDocValuesTests extends ESTestCase { | ||
|
||
public void testResize() { | ||
final int oldSize = Integer.MAX_VALUE - 200; | ||
final int newSize = Integer.MAX_VALUE - 100; | ||
// This counter should account for the initialization of the array (size == 1) | ||
// and the diff between getArrayLength() and resize() | ||
final AtomicLong counter = new AtomicLong(); | ||
LongConsumer consumer = value -> { | ||
long total = counter.addAndGet(value); | ||
assertThat(total, Matchers.greaterThanOrEqualTo(0L)); | ||
}; | ||
SortingNumericDocValues docValues = new SortingNumericDocValues(consumer) { | ||
|
||
@Override | ||
protected void growExact(int newValuesLength) { | ||
// don't grow the array | ||
} | ||
|
||
/** Get the size of the internal array using a method so we can override it during testing */ | ||
protected int getArrayLength() { | ||
return oldSize; | ||
} | ||
|
||
@Override | ||
public boolean advanceExact(int target) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int docID() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int nextDoc() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int advance(int target) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long cost() { | ||
return 0; | ||
} | ||
}; | ||
docValues.resize(newSize); | ||
final long internalNewSize = ArrayUtil.oversize(newSize, Long.BYTES); | ||
assertThat(counter.get(), Matchers.lessThan((internalNewSize + 1) * Long.BYTES)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Actually the expression above:
Can overflow as well?
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.
Because
length
andLong.BYTES
are bothint
, right?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.
yes
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.
booooo. And you can't test that one easily.
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.
yes, that is tricky to test now. we can make getLength a protected method that can be override?
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.
Yeah. I guess so. I think because this thing is designed for extension maybe we should do something else? These two new methods are only for testing which is fine if you are compositing this thing. But when you extend it its hard to know which to extend.
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.
Maybe we should be just add asserts in the code. I think this is what they are design for?
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.
Without the overrides you can't put the thing into a state where we'd see the overflows. I'd just go with the protected method and a comment, I think. I just kind of got confused.