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:25:23 -07:00
parent 5568929dd2
commit b6b01a790f
1 changed files with 11 additions and 4 deletions

View File

@ -709,8 +709,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
long ll = blockBuffer.getLongAfterPosition(offsetFromPos); long ll = blockBuffer.getLongAfterPosition(offsetFromPos);
klen = (int)(ll >> Integer.SIZE); klen = (int)(ll >> Integer.SIZE);
vlen = (int)(Bytes.MASK_FOR_LOWER_INT_IN_LONG ^ ll); vlen = (int)(Bytes.MASK_FOR_LOWER_INT_IN_LONG ^ ll);
if (klen < 0 || vlen < 0 || klen > blockBuffer.limit() if (checkKeyLen(klen) || checkLen(vlen)) {
|| vlen > blockBuffer.limit()) {
throw new IllegalStateException("Invalid klen " + klen + " or vlen " throw new IllegalStateException("Invalid klen " + klen + " or vlen "
+ vlen + ". Block offset: " + vlen + ". Block offset: "
+ curBlock.getOffset() + ", block length: " + blockBuffer.limit() + ", position: " + curBlock.getOffset() + ", block length: " + blockBuffer.limit() + ", position: "
@ -725,7 +724,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
// Read short as unsigned, high byte first // Read short as unsigned, high byte first
tlen = ((blockBuffer.getByteAfterPosition(offsetFromPos) & 0xff) << 8) tlen = ((blockBuffer.getByteAfterPosition(offsetFromPos) & 0xff) << 8)
^ (blockBuffer.getByteAfterPosition(offsetFromPos + 1) & 0xff); ^ (blockBuffer.getByteAfterPosition(offsetFromPos + 1) & 0xff);
if (tlen < 0 || tlen > blockBuffer.limit()) { if (checkLen(tlen)) {
throw new IllegalStateException("Invalid tlen " + tlen + ". Block offset: " throw new IllegalStateException("Invalid tlen " + tlen + ". Block offset: "
+ curBlock.getOffset() + ", block length: " + blockBuffer.limit() + ", position: " + curBlock.getOffset() + ", block length: " + blockBuffer.limit() + ", position: "
+ blockBuffer.position() + " (without header)."); + blockBuffer.position() + " (without header).");
@ -1139,6 +1138,14 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
return blockSeek(key, seekBefore); return blockSeek(key, seekBefore);
} }
/**
* @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 * @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.
@ -1151,7 +1158,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
* 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: " + " or currValueLen " + this.currValueLen + ". Block offset: "
+ this.curBlock.getOffset() + ", block length: " + this.curBlock.getOffset() + ", block length: "