Validate the size limit in BufferedTokenizer. (#16882)

This commit is contained in:
Mashhur 2025-01-09 15:53:07 -08:00 committed by GitHub
parent d978e07f2c
commit a215101032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View file

@ -12,7 +12,6 @@ import org.openjdk.jmh.annotations.Fork;
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;

View file

@ -61,6 +61,11 @@ describe FileWatch::BufferedTokenizer do
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

View file

@ -55,7 +55,11 @@ public class BufferedTokenizerExt extends RubyObject {
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;