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

Backport PR #16882 to 8.17: Validate the size limit in BufferedTokenizer. #16891

Merged
merged 1 commit into from
Jan 10, 2025
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
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