Skip to content

Commit

Permalink
Validate the size limit in BufferedTokenizer. (#16882)
Browse files Browse the repository at this point in the history
(cherry picked from commit a215101)
  • Loading branch information
mashhurs committed Jan 10, 2025
1 parent 946c78c commit 5a8780d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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 5a8780d

Please sign in to comment.