LUCENE-5617: don't rely on directory metadata for stored fields 'maxpointer', change to hard check

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1588498 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-04-18 15:56:21 +00:00
parent 07470a07f9
commit b9a22bb5db
1 changed files with 10 additions and 2 deletions

View File

@ -118,12 +118,12 @@ public final class CompressingStoredFieldsReader extends StoredFieldsReader {
assert CodecUtil.headerLength(codecNameIdx) == indexStream.getFilePointer();
indexReader = new CompressingStoredFieldsIndexReader(indexStream, si);
long maxPointer = -1;
if (version >= VERSION_CHECKSUM) {
maxPointer = indexStream.readVLong();
assert maxPointer + CodecUtil.footerLength() == d.fileLength(fieldsStreamFN);
CodecUtil.checkFooter(indexStream);
} else {
maxPointer = d.fileLength(fieldsStreamFN);
CodecUtil.checkEOF(indexStream);
}
indexStream.close();
@ -131,6 +131,14 @@ public final class CompressingStoredFieldsReader extends StoredFieldsReader {
// Open the data file and read metadata
fieldsStream = d.openInput(fieldsStreamFN, context);
if (version >= VERSION_CHECKSUM) {
if (maxPointer + CodecUtil.footerLength() != fieldsStream.length()) {
throw new CorruptIndexException("Invalid fieldsStream maxPointer (file truncated?): maxPointer=" + maxPointer + ", length=" + fieldsStream.length());
}
} else {
maxPointer = fieldsStream.length();
}
this.maxPointer = maxPointer;
final String codecNameDat = formatName + CODEC_SFX_DAT;
final int fieldsVersion = CodecUtil.checkHeader(fieldsStream, codecNameDat, VERSION_START, VERSION_CURRENT);
if (version != fieldsVersion) {