Repository: hbase
Updated Branches:
  refs/heads/branch-1 abfb20206 -> c80d671a0


HBASE-12949 Scanner can be stuck in infinite loop if the HFile is corrupted


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

Branch: refs/heads/branch-1
Commit: c80d671a062737c806d4e20a992443e9b6b86b02
Parents: abfb202
Author: Jerry He <jerry...@apache.org>
Authored: Wed Sep 21 13:31:18 2016 -0700
Committer: Jerry He <jerry...@apache.org>
Committed: Wed Sep 21 13:31:18 2016 -0700

----------------------------------------------------------------------
 .../apache/hadoop/hbase/io/hfile/HFileReaderV2.java | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/c80d671a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
----------------------------------------------------------------------
diff --git 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
index 786d00d..0bca8e5 100644
--- 
a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
+++ 
b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
@@ -970,6 +970,14 @@ public class HFileReaderV2 extends AbstractHFileReader {
 
     /**
      * @param v
+     * @return True if v &lt;= 0 or v &gt; current block buffer limit.
+     */
+    protected final boolean checkKeyLen(final int v) {
+      return v <= 0 || v > this.blockBuffer.limit();
+    }
+
+    /**
+     * @param v
      * @return True if v &lt; 0 or v &gt; current block buffer limit.
      */
     protected final boolean checkLen(final int v) {
@@ -980,7 +988,7 @@ public class HFileReaderV2 extends AbstractHFileReader {
      * Check key and value lengths are wholesome.
      */
     protected final void checkKeyValueLen() {
-      if (checkLen(this.currKeyLen) || checkLen(this.currValueLen)) {
+      if (checkKeyLen(this.currKeyLen) || checkLen(this.currValueLen)) {
         throw new IllegalStateException("Invalid currKeyLen " + 
this.currKeyLen +
           " or currValueLen " + this.currValueLen + ". Block offset: " + 
block.getOffset() +
           ", block length: " + this.blockBuffer.limit() + ", position: " +
@@ -1078,6 +1086,12 @@ public class HFileReaderV2 extends AbstractHFileReader {
         blockBuffer.mark();
         klen = blockBuffer.getInt();
         vlen = blockBuffer.getInt();
+        if (checkKeyLen(klen) || checkLen(vlen)) {
+          throw new IllegalStateException("Invalid klen " + klen + " or vlen "
+              + vlen + ". Block offset: "
+              + block.getOffset() + ", block length: " + blockBuffer.limit() + 
", position: "
+              + blockBuffer.position() + " (without header).");
+        }
         blockBuffer.reset();
         if (this.reader.shouldIncludeMemstoreTS()) {
           if (this.reader.decodeMemstoreTS) {

Reply via email to