LUCENE-5615: catch invalid per-segment delete counts when writing the segment

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1588459 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2014-04-18 13:08:40 +00:00
parent 8afaa1ea5b
commit 1c208440f3
3 changed files with 12 additions and 5 deletions

View File

@ -293,6 +293,9 @@ Bug fixes
* SOLR-5983: HTMLStripCharFilter is treating CDATA sections incorrectly.
(Dan Funk, Steve Rowe)
* LUCENE-5615: Validate per-segment delete counts at write time, to
help catch bugs that might otherwise cause corruption (Mike McCandless)
Test Framework
* LUCENE-5592: Incorrectly reported uncloseable files. (Dawid Weiss)

View File

@ -224,8 +224,10 @@ public class SegmentCommitInfo {
}
void setDelCount(int delCount) {
if (delCount < 0 || delCount > info.getDocCount()) {
throw new IllegalArgumentException("invalid delCount=" + delCount + " (docCount=" + info.getDocCount() + ")");
}
this.delCount = delCount;
assert delCount <= info.getDocCount();
}
/** Returns a description of this segment. */

View File

@ -346,7 +346,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
long delGen = input.readLong();
int delCount = input.readInt();
if (delCount < 0 || delCount > info.getDocCount()) {
throw new CorruptIndexException("invalid deletion count: " + delCount + " (resource: " + input + ")");
throw new CorruptIndexException("invalid deletion count: " + delCount + " vs docCount=" + info.getDocCount() + " (resource: " + input + ")");
}
long fieldInfosGen = -1;
if (format >= VERSION_46) {
@ -438,7 +438,11 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
segnOutput.writeString(si.name);
segnOutput.writeString(si.getCodec().getName());
segnOutput.writeLong(siPerCommit.getDelGen());
segnOutput.writeInt(siPerCommit.getDelCount());
int delCount = siPerCommit.getDelCount();
if (delCount < 0 || delCount > si.getDocCount()) {
throw new IllegalStateException("cannot write segment: invalid docCount segment=" + si.name + " docCount=" + si.getDocCount() + " delCount=" + delCount);
}
segnOutput.writeInt(delCount);
segnOutput.writeLong(siPerCommit.getFieldInfosGen());
final Map<Long,Set<String>> genUpdatesFiles = siPerCommit.getUpdatesFiles();
segnOutput.writeInt(genUpdatesFiles.size());
@ -447,8 +451,6 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
segnOutput.writeStringSet(e.getValue());
}
assert si.dir == directory;
assert siPerCommit.getDelCount() <= si.getDocCount();
}
segnOutput.writeStringStringMap(userData);
pendingSegnOutput = segnOutput;