mirror of https://github.com/apache/lucene.git
LUCENE-7946: Fix CharTermAttribute.setLength's bounds check
This commit is contained in:
parent
ded726ad82
commit
d7379f1dd2
|
@ -71,6 +71,9 @@ public class CharTermAttributeImpl extends AttributeImpl implements CharTermAttr
|
|||
|
||||
@Override
|
||||
public final CharTermAttribute setLength(int length) {
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("length " + length + " must not be negative");
|
||||
}
|
||||
if (length > termBuffer.length)
|
||||
throw new IllegalArgumentException("length " + length + " exceeds the size of the termBuffer (" + termBuffer.length + ")");
|
||||
termLength = length;
|
||||
|
|
|
@ -42,6 +42,16 @@ public class TestCharTermAttributeImpl extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testSetLength() {
|
||||
CharTermAttributeImpl t = new CharTermAttributeImpl();
|
||||
char[] content = "hello".toCharArray();
|
||||
t.copyBuffer(content, 0, content.length);
|
||||
IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
|
||||
t.setLength(-1);
|
||||
});
|
||||
assertTrue(expected.getMessage().contains("must not be negative"));
|
||||
}
|
||||
|
||||
public void testGrow() {
|
||||
CharTermAttributeImpl t = new CharTermAttributeImpl();
|
||||
StringBuilder buf = new StringBuilder("ab");
|
||||
|
|
Loading…
Reference in New Issue