You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/04/18 15:17:58 UTC

svn commit: r1588466 - in /lucene/dev/branches/lucene_solr_4_8: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/index/SegmentCommitInfo.java lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java

Author: mikemccand
Date: Fri Apr 18 13:17:58 2014
New Revision: 1588466

URL: http://svn.apache.org/r1588466
Log:
LUCENE-5615: catch invalid per-segment delete counts when writing the segment

Modified:
    lucene/dev/branches/lucene_solr_4_8/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/core/   (props changed)
    lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentCommitInfo.java
    lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/CHANGES.txt?rev=1588466&r1=1588465&r2=1588466&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/CHANGES.txt Fri Apr 18 13:17:58 2014
@@ -200,6 +200,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)

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentCommitInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentCommitInfo.java?rev=1588466&r1=1588465&r2=1588466&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentCommitInfo.java (original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentCommitInfo.java Fri Apr 18 13:17:58 2014
@@ -226,8 +226,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. */

Modified: lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java?rev=1588466&r1=1588465&r2=1588466&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/dev/branches/lucene_solr_4_8/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java Fri Apr 18 13:17:58 2014
@@ -348,7 +348,7 @@ public final class SegmentInfos implemen
           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 (actualFormat >= VERSION_46) {
@@ -453,7 +453,11 @@ public final class SegmentInfos implemen
         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());
@@ -463,8 +467,6 @@ public final class SegmentInfos implemen
         }
         assert si.dir == directory;
 
-        assert siPerCommit.getDelCount() <= si.getDocCount();
-
         // If this segment is pre-4.x, perform a one-time
         // "ugprade" to write the .si file for it:
         String version = si.getVersion();
@@ -484,7 +486,6 @@ public final class SegmentInfos implemen
             // kill/crash, OS crash, power loss, etc. while
             // writing the upgraded file, the marker file
             // will be missing:
-            si.addFile(markerFileName);
             IndexOutput out = directory.createOutput(markerFileName, IOContext.DEFAULT);
             try {
               CodecUtil.writeHeader(out, SEGMENT_INFO_UPGRADE_CODEC, SEGMENT_INFO_UPGRADE_VERSION);
@@ -558,7 +559,10 @@ public final class SegmentInfos implemen
     try {
       // we are about to write this SI in 3.x format, dropping all codec information, etc.
       // so it had better be a 3.x segment or you will get very confusing errors later.
-      assert si.getCodec() instanceof Lucene3xCodec : "broken test, trying to mix preflex with other codecs";
+      if ((si.getCodec() instanceof Lucene3xCodec) == false) {
+        throw new IllegalStateException("cannot write 3x SegmentInfo unless codec is Lucene3x (got: " + si.getCodec() + ")");
+      }
+
       CodecUtil.writeHeader(output, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME, 
                                     Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT);
       // Write the Lucene version that created this segment, since 3.1