-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Changes from 1 commit
4fa21cf
510fa50
bb5abb9
166cb7e
563b2b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ | |
import java.util.Map; | ||
|
||
public abstract class StringScriptFieldScript extends AbstractScriptFieldScript { | ||
/** | ||
* The maximum number of chars a script should be allowed to emit. | ||
*/ | ||
public static final long MAX_CHARS = 1024 * 1024; | ||
|
||
public static final ScriptContext<Factory> CONTEXT = newContext("string_script_field", Factory.class); | ||
|
||
static List<Whitelist> whitelist() { | ||
|
@@ -36,6 +41,7 @@ public interface LeafFactory { | |
} | ||
|
||
private final List<String> results = new ArrayList<>(); | ||
private long chars; | ||
|
||
public StringScriptFieldScript(Map<String, Object> params, SearchLookup searchLookup, LeafReaderContext ctx) { | ||
super(params, searchLookup, ctx); | ||
|
@@ -49,12 +55,20 @@ public StringScriptFieldScript(Map<String, Object> params, SearchLookup searchLo | |
*/ | ||
public final List<String> resultsForDoc(int docId) { | ||
results.clear(); | ||
chars = 0; | ||
setDocument(docId); | ||
execute(); | ||
return results; | ||
} | ||
|
||
protected final void emitValue(String v) { | ||
if (results.size() >= MAX_VALUES) { | ||
throw new IllegalArgumentException("too many runtime values"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 + "]"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]"? |
||
} | ||
results.add(v); | ||
} | ||
|
||
|
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.
this seems high