-
Notifications
You must be signed in to change notification settings - Fork 3.8k
protect against an illegal sublist if hydrants is empty #18743
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
base: master
Are you sure you want to change the base?
protect against an illegal sublist if hydrants is empty #18743
Conversation
| bytesPersisted += sink.getBytesInMemory(); | ||
|
|
||
| final int limit = sink.isWritable() ? hydrants.size() - 1 : hydrants.size(); | ||
| final int limit = sink.isWritable() ? Integer.max(0, hydrants.size() - 1) : hydrants.size(); |
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.
Is it possible to have a small UT for this?
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.
I couldn't figure out how to accomplish it. So for full disclosure the test case I came up with is courtesy of Claude coming up with a way to force the empty list of hydrants scenario. Confirmed that without the fix it is an IAE and with the change, no exception.
| /** | ||
| * Tests an edge case where a writable sink exists but has no hydrants. | ||
| * <p> | ||
| * The test scenario is somewhat unrealistic, but we are trying to prevent a regression because this issue was seen in | ||
| * the wild and resulted in failed indexing tasks due to an IAE. | ||
| * </p> | ||
| */ |
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.
I think the javadoc here can be omitted.
Also, since it was already reported, I think it is a valid scenario.
| * </p> | ||
| */ | ||
| @Test | ||
| public void testPersistAllWithEmptySink() throws Exception |
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.
Nit: update the method name to reflect the expected behaviour with the suffix IsNoop or DoesNotFail, etc.
| public void testPersistAllWithEmptySink() throws Exception | |
| public void testPersistAllWithEmptySinkIsNoop() throws Exception |
Description
If hydrants is empty here, it can lead to an IAE creating a sublist of hydrants with invalid indices.
This PR has: