diff --git a/logstash-core/benchmarks/src/main/java/org/logstash/benchmark/BufferedTokenizerExtBenchmark.java b/logstash-core/benchmarks/src/main/java/org/logstash/benchmark/BufferedTokenizerExtBenchmark.java index 024ecf442a3..5b01cebb3e5 100644 --- a/logstash-core/benchmarks/src/main/java/org/logstash/benchmark/BufferedTokenizerExtBenchmark.java +++ b/logstash-core/benchmarks/src/main/java/org/logstash/benchmark/BufferedTokenizerExtBenchmark.java @@ -12,7 +12,6 @@ import org.openjdk.jmh.annotations.Level; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OperationsPerInvocation; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.Setup; diff --git a/logstash-core/spec/logstash/util/buftok_spec.rb b/logstash-core/spec/logstash/util/buftok_spec.rb index acdf2097709..3d7b4b1990f 100644 --- a/logstash-core/spec/logstash/util/buftok_spec.rb +++ b/logstash-core/spec/logstash/util/buftok_spec.rb @@ -61,6 +61,11 @@ context 'with decode_size_limit_bytes' do subject { FileWatch::BufferedTokenizer.new("\n", 100) } + it "validates size limit" do + expect { FileWatch::BufferedTokenizer.new("\n", -101) }.to raise_error(java.lang.IllegalArgumentException, "Size limit must be positive") + expect { FileWatch::BufferedTokenizer.new("\n", 0) }.to raise_error(java.lang.IllegalArgumentException, "Size limit must be positive") + end + it "emits the contents of the buffer" do expect(subject.flush).to eq(data) end diff --git a/logstash-core/src/main/java/org/logstash/common/BufferedTokenizerExt.java b/logstash-core/src/main/java/org/logstash/common/BufferedTokenizerExt.java index f704fcb0f7f..be1c64d2356 100644 --- a/logstash-core/src/main/java/org/logstash/common/BufferedTokenizerExt.java +++ b/logstash-core/src/main/java/org/logstash/common/BufferedTokenizerExt.java @@ -55,7 +55,11 @@ public IRubyObject init(final ThreadContext context, IRubyObject[] args) { this.delimiter = args[0].convertToString(); } if (args.length == 2) { - this.sizeLimit = args[1].convertToInteger().getIntValue(); + final int sizeLimit = args[1].convertToInteger().getIntValue(); + if (sizeLimit <= 0) { + throw new IllegalArgumentException("Size limit must be positive"); + } + this.sizeLimit = sizeLimit; this.hasSizeLimit = true; } this.inputSize = 0;