Skip to content

Apache Lucene open-source search software

LUCENE-7592: if segments file is truncated, throw CorruptIndexException

Mike McCandlesse4f31fab2f98
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 15b89f09f2f..f38c0d5afda 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -138,6 +138,10 @@ Improvements
necessarily refer to that field (AKA requireFieldMatch==false). Disabled by default.
See UH get/setFieldMatcher. (Jim Ferenczi via David Smiley)
+* LUCENE-7592: If the segments file is truncated, we now throw
+ CorruptIndexException instead of the more confusing EOFException
+ (Mike Drob via Mike McCandless)
+
Optimizations
* LUCENE-7568: Optimize merging when index sorting is used but the
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
index 8f627cd743d..3e8b1f871bd 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -17,6 +17,7 @@
package org.apache.lucene.index;
+import java.io.EOFException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
@@ -277,7 +278,11 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
long generation = generationFromSegmentsFileName(segmentFileName);
//System.out.println(Thread.currentThread() + ": SegmentInfos.readCommit " + segmentFileName);
try (ChecksumIndexInput input = directory.openChecksumInput(segmentFileName, IOContext.READ)) {
- return readCommit(directory, input, generation);
+ try {
+ return readCommit(directory, input, generation);
+ } catch (EOFException e) {
+ throw new CorruptIndexException("Unexpected end of file while reading index.", input, e);
+ }
}
}