You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2017/09/06 09:39:11 UTC

[09/50] lucene-solr:jira/solr-10990: LUCENE-7946: Fix CharTermAttribute.setLength's bounds check

LUCENE-7946: Fix CharTermAttribute.setLength's bounds check


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d7379f1d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d7379f1d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d7379f1d

Branch: refs/heads/jira/solr-10990
Commit: d7379f1dd2baee50d7dfd2fb8767c968c982c001
Parents: ded726a
Author: Robert Muir <rm...@apache.org>
Authored: Thu Aug 31 22:29:38 2017 -0400
Committer: Robert Muir <rm...@apache.org>
Committed: Thu Aug 31 22:31:46 2017 -0400

----------------------------------------------------------------------
 .../analysis/tokenattributes/CharTermAttributeImpl.java   |  3 +++
 .../tokenattributes/TestCharTermAttributeImpl.java        | 10 ++++++++++
 2 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d7379f1d/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java b/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
index 9a5b9fa..355f417 100644
--- a/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
+++ b/lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/CharTermAttributeImpl.java
@@ -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;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d7379f1d/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java b/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
index 81dd576..3082129 100644
--- a/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
+++ b/lucene/core/src/test/org/apache/lucene/analysis/tokenattributes/TestCharTermAttributeImpl.java
@@ -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");