mirror of https://github.com/apache/lucene.git
LUCENE-5830: Fix some missing/assert codec checks to throw CorruptIndexException
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1611471 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63a925d578
commit
92bb1803ff
|
@ -135,18 +135,27 @@ public final class BlockTreeTermsReader extends FieldsProducer {
|
|||
for(int i=0;i<numFields;i++) {
|
||||
final int field = in.readVInt();
|
||||
final long numTerms = in.readVLong();
|
||||
assert numTerms >= 0;
|
||||
if (numTerms <= 0) {
|
||||
throw new CorruptIndexException("Illegal numTerms for field number: " + field + " (resource=" + in + ")");
|
||||
}
|
||||
final int numBytes = in.readVInt();
|
||||
if (numBytes < 0) {
|
||||
throw new CorruptIndexException("invalid rootCode for field number: " + field + ", numBytes=" + numBytes + " (resource=" + in + ")");
|
||||
}
|
||||
final BytesRef rootCode = new BytesRef(new byte[numBytes]);
|
||||
in.readBytes(rootCode.bytes, 0, numBytes);
|
||||
rootCode.length = numBytes;
|
||||
final FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
|
||||
assert fieldInfo != null: "field=" + field;
|
||||
if (fieldInfo == null) {
|
||||
throw new CorruptIndexException("invalid field number: " + field + ", resource=" + in + ")");
|
||||
}
|
||||
final long sumTotalTermFreq = fieldInfo.getIndexOptions() == IndexOptions.DOCS_ONLY ? -1 : in.readVLong();
|
||||
final long sumDocFreq = in.readVLong();
|
||||
final int docCount = in.readVInt();
|
||||
final int longsSize = version >= BlockTreeTermsWriter.VERSION_META_ARRAY ? in.readVInt() : 0;
|
||||
|
||||
if (longsSize < 0) {
|
||||
throw new CorruptIndexException("invalid longsSize for field: " + fieldInfo.name + ", longsSize=" + longsSize + " (resource=" + in + ")");
|
||||
}
|
||||
BytesRef minTerm, maxTerm;
|
||||
if (version >= BlockTreeTermsWriter.VERSION_MIN_MAX_TERMS) {
|
||||
minTerm = readBytesRef(in);
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Collection;
|
|||
|
||||
import org.apache.lucene.codecs.CodecUtil;
|
||||
import org.apache.lucene.codecs.LiveDocsFormat;
|
||||
import org.apache.lucene.index.CorruptIndexException;
|
||||
import org.apache.lucene.index.IndexFileNames;
|
||||
import org.apache.lucene.index.SegmentCommitInfo;
|
||||
import org.apache.lucene.store.DataOutput; // javadocs
|
||||
|
@ -88,9 +89,12 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {
|
|||
public Bits readLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) throws IOException {
|
||||
String filename = IndexFileNames.fileNameFromGeneration(info.info.name, DELETES_EXTENSION, info.getDelGen());
|
||||
final BitVector liveDocs = new BitVector(dir, filename, context);
|
||||
assert liveDocs.count() == info.info.getDocCount() - info.getDelCount():
|
||||
"liveDocs.count()=" + liveDocs.count() + " info.docCount=" + info.info.getDocCount() + " info.getDelCount()=" + info.getDelCount();
|
||||
assert liveDocs.length() == info.info.getDocCount();
|
||||
if (liveDocs.length() != info.info.getDocCount()) {
|
||||
throw new CorruptIndexException("liveDocs.length()=" + liveDocs.length() + "info.docCount=" + info.info.getDocCount() + " (filename=" + filename + ")");
|
||||
}
|
||||
if (liveDocs.count() != info.info.getDocCount() - info.getDelCount()) {
|
||||
throw new CorruptIndexException("liveDocs.count()=" + liveDocs.count() + " info.docCount=" + info.info.getDocCount() + " info.getDelCount()=" + info.getDelCount() + " (filename=" + filename + ")");
|
||||
}
|
||||
return liveDocs;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,9 @@ final class Lucene46FieldInfosReader extends FieldInfosReader {
|
|||
for (int i = 0; i < size; i++) {
|
||||
String name = input.readString();
|
||||
final int fieldNumber = input.readVInt();
|
||||
if (fieldNumber < 0) {
|
||||
throw new CorruptIndexException("invalid field number for field: " + name + ", fieldNumber=" + fieldNumber + " (resource=" + input + ")");
|
||||
}
|
||||
byte bits = input.readByte();
|
||||
boolean isIndexed = (bits & Lucene46FieldInfosFormat.IS_INDEXED) != 0;
|
||||
boolean storeTermVector = (bits & Lucene46FieldInfosFormat.STORE_TERMVECTOR) != 0;
|
||||
|
|
Loading…
Reference in New Issue