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

Fix possible OOM caused by huge repetitions of inserts (fixes #863) #878

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ public interface LineReader {
*/
String SUGGESTIONS_MIN_BUFFER_SIZE = "suggestions-min-buffer-size";

/**
* Max number of times a command can be repeated.
*/
String MAX_REPEAT_COUNT = "max-repeat-count";

Map<String, KeyMap<Binding>> defaultKeyMaps();

enum Option {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class LineReaderImpl implements LineReader, Flushable {

public static final String FOCUS_IN_SEQ = "\033[I";
public static final String FOCUS_OUT_SEQ = "\033[O";
public static final int DEFAULT_MAX_REPEAT_COUNT = 9999;

/**
* Possible states in which the current readline operation may be in.
Expand Down Expand Up @@ -2392,6 +2393,10 @@ protected boolean negArgument() {
protected boolean digitArgument() {
String s = getLastBinding();
repeatCount = (repeatCount * 10) + s.charAt(s.length() - 1) - '0';
int maxRepeatCount = getInt(MAX_REPEAT_COUNT, DEFAULT_MAX_REPEAT_COUNT);
if (repeatCount > maxRepeatCount) {
throw new IllegalArgumentException("digit argument should be less than " + maxRepeatCount);
}
isArgDigit = true;
return true;
}
Expand Down
Loading