hbase git commit: HBASE-21401 Sanity check in BaseDecoder#parseCell
Repository: hbase Updated Branches: refs/heads/branch-2.1 0250b4b53 -> 0ec9f81bc HBASE-21401 Sanity check in BaseDecoder#parseCell Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0ec9f81b Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0ec9f81b Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0ec9f81b Branch: refs/heads/branch-2.1 Commit: 0ec9f81bc8c0f2c07930ae9e89635b4574ad690f Parents: 0250b4b Author: huzheng Authored: Sat Oct 27 16:57:01 2018 +0800 Committer: huzheng Committed: Thu Nov 8 20:28:48 2018 +0800 -- .../java/org/apache/hadoop/hbase/KeyValue.java | 9 + .../org/apache/hadoop/hbase/KeyValueUtil.java | 149 +- .../hadoop/hbase/codec/KeyValueCodec.java | 3 +- .../hbase/codec/KeyValueCodecWithTags.java | 2 +- .../hbase/io/encoding/RowIndexSeekerV1.java | 2 +- .../org/apache/hadoop/hbase/TestKeyValue.java | 296 +-- .../hadoop/hbase/regionserver/HStore.java | 1 - 7 files changed, 284 insertions(+), 178 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hbase/blob/0ec9f81b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index f7f6c0d..f913124 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -252,6 +252,15 @@ public class KeyValue implements ExtendedCell, Cloneable { } /** + * True to indicate that the byte b is a valid type. + * @param b byte to check + * @return true or false + */ +static boolean isValidType(byte b) { + return codeArray[b & 0xff] != null; +} + +/** * Cannot rely on enum ordinals . They change if item is removed or moved. * Do our own codes. * @param b http://git-wip-us.apache.org/repos/asf/hbase/blob/0ec9f81b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index 1b61d1e..fbec792 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -518,17 +518,145 @@ public class KeyValueUtil { return (long) length + Bytes.SIZEOF_INT; } + static String bytesToHex(byte[] buf, int offset, int length) { +return ", KeyValueBytesHex=" + Bytes.toStringBinary(buf, offset, length) + ", offset=" + offset ++ ", length=" + length; + } + + private static void checkKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) + throws IOException { +int pos = offset, endOffset = offset + length; +// check the key +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException( + "Overflow when reading key length at position=" + pos + bytesToHex(buf, offset, length)); +} +int keyLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (keyLen <= 0 || pos + keyLen > endOffset) { + throw new IOException( + "Invalid key length in KeyValue. keyLength=" + keyLen + bytesToHex(buf, offset, length)); +} +// check the value +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException("Overflow when reading value length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int valLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (valLen < 0 || pos + valLen > endOffset) { + throw new IOException("Invalid value length in KeyValue, valueLength=" + valLen + + bytesToHex(buf, offset, length)); +} +// check the row +if (pos + Bytes.SIZEOF_SHORT > endOffset) { + throw new IOException( + "Overflow when reading row length at position=" + pos + bytesToHex(buf, offset, length)); +} +short rowLen = Bytes.toShort(buf, pos, Bytes.SIZEOF_SHORT); +pos += Bytes.SIZEOF_SHORT; +if (rowLen < 0 || pos + rowLen > endOffset) { + throw new IOException( + "Invalid row length in KeyValue, rowLength=" + rowLen + bytesToHex(buf, offset, length)); +} +pos += rowLen; +// check the family +if (pos + Bytes.SIZEOF_BYTE > endOffset) { + throw new IOException("Overflow when reading family length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int familyLen = buf[pos]; +pos +=
hbase git commit: HBASE-21401 Sanity check in BaseDecoder#parseCell
Repository: hbase Updated Branches: refs/heads/branch-2.0 d70308160 -> 5fff00419 HBASE-21401 Sanity check in BaseDecoder#parseCell Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/5fff0041 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5fff0041 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5fff0041 Branch: refs/heads/branch-2.0 Commit: 5fff00419baa66998a71d189de026a9fbda66fd3 Parents: d703081 Author: huzheng Authored: Sat Oct 27 16:57:01 2018 +0800 Committer: huzheng Committed: Thu Nov 8 20:25:06 2018 +0800 -- .../java/org/apache/hadoop/hbase/KeyValue.java | 9 + .../org/apache/hadoop/hbase/KeyValueUtil.java | 149 +- .../hadoop/hbase/codec/KeyValueCodec.java | 3 +- .../hbase/codec/KeyValueCodecWithTags.java | 2 +- .../hbase/io/encoding/RowIndexSeekerV1.java | 2 +- .../org/apache/hadoop/hbase/TestKeyValue.java | 296 +-- .../hadoop/hbase/regionserver/HStore.java | 1 - 7 files changed, 284 insertions(+), 178 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hbase/blob/5fff0041/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index f7f6c0d..f913124 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -252,6 +252,15 @@ public class KeyValue implements ExtendedCell, Cloneable { } /** + * True to indicate that the byte b is a valid type. + * @param b byte to check + * @return true or false + */ +static boolean isValidType(byte b) { + return codeArray[b & 0xff] != null; +} + +/** * Cannot rely on enum ordinals . They change if item is removed or moved. * Do our own codes. * @param b http://git-wip-us.apache.org/repos/asf/hbase/blob/5fff0041/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index 1b61d1e..fbec792 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -518,17 +518,145 @@ public class KeyValueUtil { return (long) length + Bytes.SIZEOF_INT; } + static String bytesToHex(byte[] buf, int offset, int length) { +return ", KeyValueBytesHex=" + Bytes.toStringBinary(buf, offset, length) + ", offset=" + offset ++ ", length=" + length; + } + + private static void checkKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) + throws IOException { +int pos = offset, endOffset = offset + length; +// check the key +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException( + "Overflow when reading key length at position=" + pos + bytesToHex(buf, offset, length)); +} +int keyLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (keyLen <= 0 || pos + keyLen > endOffset) { + throw new IOException( + "Invalid key length in KeyValue. keyLength=" + keyLen + bytesToHex(buf, offset, length)); +} +// check the value +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException("Overflow when reading value length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int valLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (valLen < 0 || pos + valLen > endOffset) { + throw new IOException("Invalid value length in KeyValue, valueLength=" + valLen + + bytesToHex(buf, offset, length)); +} +// check the row +if (pos + Bytes.SIZEOF_SHORT > endOffset) { + throw new IOException( + "Overflow when reading row length at position=" + pos + bytesToHex(buf, offset, length)); +} +short rowLen = Bytes.toShort(buf, pos, Bytes.SIZEOF_SHORT); +pos += Bytes.SIZEOF_SHORT; +if (rowLen < 0 || pos + rowLen > endOffset) { + throw new IOException( + "Invalid row length in KeyValue, rowLength=" + rowLen + bytesToHex(buf, offset, length)); +} +pos += rowLen; +// check the family +if (pos + Bytes.SIZEOF_BYTE > endOffset) { + throw new IOException("Overflow when reading family length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int familyLen = buf[pos]; +pos +=
hbase git commit: HBASE-21401 Sanity check in BaseDecoder#parseCell
Repository: hbase Updated Branches: refs/heads/branch-2 565ea7ad0 -> b6d32e8a1 HBASE-21401 Sanity check in BaseDecoder#parseCell Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/b6d32e8a Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/b6d32e8a Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/b6d32e8a Branch: refs/heads/branch-2 Commit: b6d32e8a1082a694dab0be94682324734363ec34 Parents: 565ea7a Author: huzheng Authored: Sat Oct 27 16:57:01 2018 +0800 Committer: huzheng Committed: Thu Nov 8 20:14:03 2018 +0800 -- .../java/org/apache/hadoop/hbase/KeyValue.java | 9 + .../org/apache/hadoop/hbase/KeyValueUtil.java | 149 +- .../hadoop/hbase/codec/KeyValueCodec.java | 3 +- .../hbase/codec/KeyValueCodecWithTags.java | 2 +- .../hbase/io/encoding/RowIndexSeekerV1.java | 2 +- .../org/apache/hadoop/hbase/TestKeyValue.java | 296 +-- .../hadoop/hbase/regionserver/HStore.java | 1 - 7 files changed, 284 insertions(+), 178 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hbase/blob/b6d32e8a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index f7f6c0d..f913124 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -252,6 +252,15 @@ public class KeyValue implements ExtendedCell, Cloneable { } /** + * True to indicate that the byte b is a valid type. + * @param b byte to check + * @return true or false + */ +static boolean isValidType(byte b) { + return codeArray[b & 0xff] != null; +} + +/** * Cannot rely on enum ordinals . They change if item is removed or moved. * Do our own codes. * @param b http://git-wip-us.apache.org/repos/asf/hbase/blob/b6d32e8a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index 1b61d1e..fbec792 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -518,17 +518,145 @@ public class KeyValueUtil { return (long) length + Bytes.SIZEOF_INT; } + static String bytesToHex(byte[] buf, int offset, int length) { +return ", KeyValueBytesHex=" + Bytes.toStringBinary(buf, offset, length) + ", offset=" + offset ++ ", length=" + length; + } + + private static void checkKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) + throws IOException { +int pos = offset, endOffset = offset + length; +// check the key +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException( + "Overflow when reading key length at position=" + pos + bytesToHex(buf, offset, length)); +} +int keyLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (keyLen <= 0 || pos + keyLen > endOffset) { + throw new IOException( + "Invalid key length in KeyValue. keyLength=" + keyLen + bytesToHex(buf, offset, length)); +} +// check the value +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException("Overflow when reading value length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int valLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (valLen < 0 || pos + valLen > endOffset) { + throw new IOException("Invalid value length in KeyValue, valueLength=" + valLen + + bytesToHex(buf, offset, length)); +} +// check the row +if (pos + Bytes.SIZEOF_SHORT > endOffset) { + throw new IOException( + "Overflow when reading row length at position=" + pos + bytesToHex(buf, offset, length)); +} +short rowLen = Bytes.toShort(buf, pos, Bytes.SIZEOF_SHORT); +pos += Bytes.SIZEOF_SHORT; +if (rowLen < 0 || pos + rowLen > endOffset) { + throw new IOException( + "Invalid row length in KeyValue, rowLength=" + rowLen + bytesToHex(buf, offset, length)); +} +pos += rowLen; +// check the family +if (pos + Bytes.SIZEOF_BYTE > endOffset) { + throw new IOException("Overflow when reading family length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int familyLen = buf[pos]; +pos += Bytes.SIZEOF_BYTE;
hbase git commit: HBASE-21401 Sanity check in BaseDecoder#parseCell
Repository: hbase Updated Branches: refs/heads/master cf9b51556 -> f17382792 HBASE-21401 Sanity check in BaseDecoder#parseCell Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/f1738279 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/f1738279 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/f1738279 Branch: refs/heads/master Commit: f17382792fc9d9eb7aeedbaa7faa48ce6dbd42d4 Parents: cf9b515 Author: huzheng Authored: Sat Oct 27 16:57:01 2018 +0800 Committer: huzheng Committed: Thu Nov 8 20:07:04 2018 +0800 -- .../java/org/apache/hadoop/hbase/KeyValue.java | 9 + .../org/apache/hadoop/hbase/KeyValueUtil.java | 149 +- .../hadoop/hbase/codec/KeyValueCodec.java | 3 +- .../hbase/codec/KeyValueCodecWithTags.java | 2 +- .../hbase/io/encoding/RowIndexSeekerV1.java | 2 +- .../org/apache/hadoop/hbase/TestKeyValue.java | 295 +-- .../hadoop/hbase/regionserver/HStore.java | 1 - 7 files changed, 283 insertions(+), 178 deletions(-) -- http://git-wip-us.apache.org/repos/asf/hbase/blob/f1738279/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index f7f6c0d..f913124 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -252,6 +252,15 @@ public class KeyValue implements ExtendedCell, Cloneable { } /** + * True to indicate that the byte b is a valid type. + * @param b byte to check + * @return true or false + */ +static boolean isValidType(byte b) { + return codeArray[b & 0xff] != null; +} + +/** * Cannot rely on enum ordinals . They change if item is removed or moved. * Do our own codes. * @param b http://git-wip-us.apache.org/repos/asf/hbase/blob/f1738279/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java -- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index 1b61d1e..fbec792 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -518,17 +518,145 @@ public class KeyValueUtil { return (long) length + Bytes.SIZEOF_INT; } + static String bytesToHex(byte[] buf, int offset, int length) { +return ", KeyValueBytesHex=" + Bytes.toStringBinary(buf, offset, length) + ", offset=" + offset ++ ", length=" + length; + } + + private static void checkKeyValueBytes(byte[] buf, int offset, int length, boolean withTags) + throws IOException { +int pos = offset, endOffset = offset + length; +// check the key +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException( + "Overflow when reading key length at position=" + pos + bytesToHex(buf, offset, length)); +} +int keyLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (keyLen <= 0 || pos + keyLen > endOffset) { + throw new IOException( + "Invalid key length in KeyValue. keyLength=" + keyLen + bytesToHex(buf, offset, length)); +} +// check the value +if (pos + Bytes.SIZEOF_INT > endOffset) { + throw new IOException("Overflow when reading value length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int valLen = Bytes.toInt(buf, pos, Bytes.SIZEOF_INT); +pos += Bytes.SIZEOF_INT; +if (valLen < 0 || pos + valLen > endOffset) { + throw new IOException("Invalid value length in KeyValue, valueLength=" + valLen + + bytesToHex(buf, offset, length)); +} +// check the row +if (pos + Bytes.SIZEOF_SHORT > endOffset) { + throw new IOException( + "Overflow when reading row length at position=" + pos + bytesToHex(buf, offset, length)); +} +short rowLen = Bytes.toShort(buf, pos, Bytes.SIZEOF_SHORT); +pos += Bytes.SIZEOF_SHORT; +if (rowLen < 0 || pos + rowLen > endOffset) { + throw new IOException( + "Invalid row length in KeyValue, rowLength=" + rowLen + bytesToHex(buf, offset, length)); +} +pos += rowLen; +// check the family +if (pos + Bytes.SIZEOF_BYTE > endOffset) { + throw new IOException("Overflow when reading family length at position=" + pos + + bytesToHex(buf, offset, length)); +} +int familyLen = buf[pos]; +pos += Bytes.SIZEOF_BYTE; +