Skip to content

Commit

Permalink
Fix possible OOM caused by huge repetitions of inserts (fixes #863) (#…
Browse files Browse the repository at this point in the history
…878)

Introduce a max-repeat-count integer option
  • Loading branch information
gnodet authored Oct 24, 2023
1 parent 8805647 commit 7aa9c5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit 7aa9c5e

Please sign in to comment.