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

Stop runtime script from emitting too many values #61938

Merged

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Sep 3, 2020

This prevent keyword valued runtime scripts from emitting too many
values or values that take up too much space. Without this you can put
allocate a ton of memory with the script by sticking it into a tight
loop. Painless has some protections against this but:

  1. I don't want to rely on them out of sheer paranoia
  2. They don't really kick in when the script uses callbacks like we do
    anyway.

Relates to #59332

This prevent `keyword` valued runtime scripts from emitting too many
values or values that take up too much space. Without this you can put
allocate a ton of memory with the script by sticking it into a tight
loop. Painless has some protections against this but:
1. I don't want to rely on them out of sheer paranoia
2. They don't really kick in when the script uses callbacks like we do
   anyway.

Relates to elastic#59332
@nik9000 nik9000 added >non-issue :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.10.0 labels Sep 3, 2020
@nik9000 nik9000 requested a review from javanna September 3, 2020 16:45
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Sep 3, 2020
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

the approach looks good to me, I guess the plan is to apply it to all types and share as much code as possible?

/**
* The maximum number of values a script should be allowed to emit.
*/
public static final int MAX_VALUES = 1000;
Copy link
Member

Choose a reason for hiding this comment

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

this seems high

setDocument(docId);
execute();
return results;
}

protected final void emitValue(String v) {
if (results.size() >= MAX_VALUES) {
throw new IllegalArgumentException("too many runtime values");
}
Copy link
Member

Choose a reason for hiding this comment

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

could the max values check be shared in the base class, and could we then unify the error message to something like "Runtime field [field] is emitting [1500] values while the maximum number of values allowed is [1000]"?

}
chars += v.length();
if (chars >= MAX_CHARS) {
throw new IllegalArgumentException("too many characters in runtime values [" + chars + "]");
Copy link
Member

Choose a reason for hiding this comment

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

Runtime field [field] is emitting [1500] characters while the maximum number of characters allowed is [1000]"?

@nik9000
Copy link
Member Author

nik9000 commented Sep 4, 2020 via email

@javanna
Copy link
Member

javanna commented Sep 4, 2020

Does 100 sound reasonable for the max values?

@nik9000
Copy link
Member Author

nik9000 commented Sep 4, 2020 via email

@nik9000 nik9000 requested a review from javanna September 4, 2020 16:04
@nik9000
Copy link
Member Author

nik9000 commented Sep 4, 2020

@javanna this is ready for you again!

@javanna javanna mentioned this pull request Sep 9, 2020
30 tasks
@nik9000 nik9000 requested a review from javanna September 9, 2020 14:47
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

LGTM thanks @nik9000 !

@nik9000
Copy link
Member Author

nik9000 commented Sep 9, 2020

Thanks @javanna !

@nik9000 nik9000 merged commit 7f542e0 into elastic:master Sep 9, 2020
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Sep 9, 2020
This prevent `keyword` valued runtime scripts from emitting too many
values or values that take up too much space. Without this you can put
allocate a ton of memory with the script by sticking it into a tight
loop. Painless has some protections against this but:
1. I don't want to rely on them out of sheer paranoia
2. They don't really kick in when the script uses callbacks like we do
   anyway.

Relates to elastic#59332
nik9000 added a commit that referenced this pull request Sep 9, 2020
This prevent `keyword` valued runtime scripts from emitting too many
values or values that take up too much space. Without this you can put
allocate a ton of memory with the script by sticking it into a tight
loop. Painless has some protections against this but:
1. I don't want to rely on them out of sheer paranoia
2. They don't really kick in when the script uses callbacks like we do
   anyway.

Relates to #59332
@javanna javanna added v7.11.0 and removed v7.10.0 labels Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants