HBASE-22032 KeyValue validation should check for null byte array
Signed-off-by: Andrew Purtell <apurtell@apache.org>
This commit is contained in:
parent
01e5af5a34
commit
d4c37778ee
|
@ -509,11 +509,17 @@ public class KeyValueUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String bytesToHex(byte[] buf, int offset, int length) {
|
static String bytesToHex(byte[] buf, int offset, int length) {
|
||||||
return ", KeyValueBytesHex=" + Bytes.toStringBinary(buf, offset, length) + ", offset=" + offset
|
String bufferContents = buf != null ? Bytes.toStringBinary(buf, offset, length) : "<null>";
|
||||||
|
return ", KeyValueBytesHex=" + bufferContents + ", offset=" + offset
|
||||||
+ ", length=" + length;
|
+ ", length=" + length;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void checkKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) {
|
static void checkKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) {
|
||||||
|
if (buf == null) {
|
||||||
|
throw new IllegalArgumentException("Invalid to have null " +
|
||||||
|
"byte array in KeyValue.");
|
||||||
|
}
|
||||||
|
|
||||||
int pos = offset, endOffset = offset + length;
|
int pos = offset, endOffset = offset + length;
|
||||||
// check the key
|
// check the key
|
||||||
if (pos + Bytes.SIZEOF_INT > endOffset) {
|
if (pos + Bytes.SIZEOF_INT > endOffset) {
|
||||||
|
|
|
@ -623,6 +623,20 @@ public class TestKeyValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullByteArrayKeyValueFailure() {
|
||||||
|
//can't add to testCheckKeyValueBytesFailureCase because it
|
||||||
|
//goes through the InputStream KeyValue API which can't produce a null buffer
|
||||||
|
try {
|
||||||
|
KeyValue kv = new KeyValue(null, 0, 0);
|
||||||
|
} catch (IllegalArgumentException iae){
|
||||||
|
assertEquals("Invalid to have null byte array in KeyValue.", iae.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fail("Should have thrown an IllegalArgumentException when " +
|
||||||
|
"creating a KeyValue with a null buffer");
|
||||||
|
}
|
||||||
|
|
||||||
private static class FailureCase {
|
private static class FailureCase {
|
||||||
byte[] buf;
|
byte[] buf;
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -681,7 +695,7 @@ public class TestKeyValue {
|
||||||
"Overflow when reading family length at position=13",
|
"Overflow when reading family length at position=13",
|
||||||
"Invalid family length in KeyValue, familyLength=1", "Timestamp cannot be negative, ts=-1",
|
"Invalid family length in KeyValue, familyLength=1", "Timestamp cannot be negative, ts=-1",
|
||||||
"Invalid type in KeyValue, type=3", "Overflow when reading value part at position=25",
|
"Invalid type in KeyValue, type=3", "Overflow when reading value part at position=25",
|
||||||
"Invalid tags length in KeyValue at position=26", };
|
"Invalid tags length in KeyValue at position=26"};
|
||||||
byte[][] withTagsInputs = new byte[][] {
|
byte[][] withTagsInputs = new byte[][] {
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x01"), // case.13
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x01"), // case.13
|
||||||
|
|
Loading…
Reference in New Issue