Skip to content

Commit

Permalink
Validate the size limit in BufferedTokenizer. (#16882)
Browse files Browse the repository at this point in the history
  • Loading branch information
mashhurs authored Jan 9, 2025
1 parent d978e07 commit a215101
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions logstash-core/spec/logstash/util/buftok_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a215101

Please sign in to comment.