HBASE-23119 ArrayIndexOutOfBoundsException in PrivateCellUtil#qualifierStartsWith (#688)
Signed-off-by: Peter Somogyi <psomogyi@apache.org> Signed-off-by: Viraj Jasani <virajjasani007@gmail.com>
This commit is contained in:
parent
b5a396749d
commit
e3078aa5aa
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.hadoop.hbase.filter;
|
package org.apache.hadoop.hbase.filter;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -97,5 +98,12 @@ public class TestComparators {
|
||||||
comparable = new SubstringComparator("cf");
|
comparable = new SubstringComparator("cf");
|
||||||
assertEquals(0, PrivateCellUtil.compareFamily(bbCell, comparable));
|
assertEquals(0, PrivateCellUtil.compareFamily(bbCell, comparable));
|
||||||
assertEquals(0, PrivateCellUtil.compareFamily(kv, comparable));
|
assertEquals(0, PrivateCellUtil.compareFamily(kv, comparable));
|
||||||
|
// Qualifier starts with
|
||||||
|
kv = new KeyValue(r1, f, q1, v2);
|
||||||
|
assertTrue(PrivateCellUtil.qualifierStartsWith(kv, Bytes.toBytes("q")));
|
||||||
|
assertTrue(PrivateCellUtil.qualifierStartsWith(kv, q1));
|
||||||
|
assertFalse(PrivateCellUtil.qualifierStartsWith(kv, q2));
|
||||||
|
assertFalse(PrivateCellUtil.qualifierStartsWith(kv, Bytes.toBytes("longerthanthequalifier")));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -767,6 +767,9 @@ public final class PrivateCellUtil {
|
||||||
if (startsWith == null || startsWith.length == 0) {
|
if (startsWith == null || startsWith.length == 0) {
|
||||||
throw new IllegalArgumentException("Cannot pass an empty startsWith");
|
throw new IllegalArgumentException("Cannot pass an empty startsWith");
|
||||||
}
|
}
|
||||||
|
if (left.getQualifierLength() < startsWith.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (left instanceof ByteBufferExtendedCell) {
|
if (left instanceof ByteBufferExtendedCell) {
|
||||||
return ByteBufferUtils.equals(((ByteBufferExtendedCell) left).getQualifierByteBuffer(),
|
return ByteBufferUtils.equals(((ByteBufferExtendedCell) left).getQualifierByteBuffer(),
|
||||||
((ByteBufferExtendedCell) left).getQualifierPosition(), startsWith.length,
|
((ByteBufferExtendedCell) left).getQualifierPosition(), startsWith.length,
|
||||||
|
|
Loading…
Reference in New Issue