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

This commit is contained in:
Jerry He 2016-09-21 13:31:18 -07:00
parent abfb20206d
commit c80d671a06
1 changed files with 15 additions and 1 deletions

View File

@ -968,6 +968,14 @@ public class HFileReaderV2 extends AbstractHFileReader {
this.nextIndexedKey = null; this.nextIndexedKey = null;
} }
/**
* @param v
* @return True if v <= 0 or v > current block buffer limit.
*/
protected final boolean checkKeyLen(final int v) {
return v <= 0 || v > this.blockBuffer.limit();
}
/** /**
* @param v * @param v
* @return True if v &lt; 0 or v &gt; current block buffer limit. * @return True if v &lt; 0 or v &gt; current block buffer limit.
@ -980,7 +988,7 @@ public class HFileReaderV2 extends AbstractHFileReader {
* Check key and value lengths are wholesome. * Check key and value lengths are wholesome.
*/ */
protected final void checkKeyValueLen() { 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 + throw new IllegalStateException("Invalid currKeyLen " + this.currKeyLen +
" or currValueLen " + this.currValueLen + ". Block offset: " + block.getOffset() + " or currValueLen " + this.currValueLen + ". Block offset: " + block.getOffset() +
", block length: " + this.blockBuffer.limit() + ", position: " + ", block length: " + this.blockBuffer.limit() + ", position: " +
@ -1078,6 +1086,12 @@ public class HFileReaderV2 extends AbstractHFileReader {
blockBuffer.mark(); blockBuffer.mark();
klen = blockBuffer.getInt(); klen = blockBuffer.getInt();
vlen = 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(); blockBuffer.reset();
if (this.reader.shouldIncludeMemstoreTS()) { if (this.reader.shouldIncludeMemstoreTS()) {
if (this.reader.decodeMemstoreTS) { if (this.reader.decodeMemstoreTS) {