mirror of https://github.com/apache/lucene.git
LUCENE-7831: CodecUtil should not seek to negative offsets.
This commit is contained in:
parent
851678388d
commit
9e1fcb0eb4
|
@ -93,7 +93,10 @@ Other
|
|||
(Daniel Jelinski via Adrien Grand)
|
||||
|
||||
======================= Lucene 6.7.0 =======================
|
||||
(No Changes)
|
||||
|
||||
Bug Fixes
|
||||
|
||||
* LUCENE-7831: CodecUtil should not seek to negative offsets. (Adrien Grand)
|
||||
|
||||
======================= Lucene 6.6.0 =======================
|
||||
|
||||
|
|
|
@ -331,6 +331,9 @@ public final class CodecUtil {
|
|||
/** Retrieves the full footer from the provided {@link IndexInput}. This throws
|
||||
* {@link CorruptIndexException} if this file does not have a valid footer. */
|
||||
public static byte[] readFooter(IndexInput in) throws IOException {
|
||||
if (in.length() < footerLength()) {
|
||||
throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), in);
|
||||
}
|
||||
in.seek(in.length() - footerLength());
|
||||
validateFooter(in);
|
||||
in.seek(in.length() - footerLength());
|
||||
|
@ -516,6 +519,9 @@ public final class CodecUtil {
|
|||
clone.seek(0);
|
||||
ChecksumIndexInput in = new BufferedChecksumIndexInput(clone);
|
||||
assert in.getFilePointer() == 0;
|
||||
if (in.length() < footerLength()) {
|
||||
throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), input);
|
||||
}
|
||||
in.seek(in.length() - footerLength());
|
||||
return checkFooter(in);
|
||||
}
|
||||
|
|
|
@ -303,4 +303,17 @@ public class TestCodecUtil extends LuceneTestCase {
|
|||
fakeChecksum.set((1L << 32) - 1); // ok
|
||||
CodecUtil.writeCRC(fakeOutput);
|
||||
}
|
||||
|
||||
public void testTruncatedFileThrowsCorruptIndexException() throws IOException {
|
||||
RAMFile file = new RAMFile();
|
||||
IndexOutput output = new RAMOutputStream(file, false);
|
||||
output.close();
|
||||
IndexInput input = new RAMInputStream("file", file);
|
||||
CorruptIndexException e = expectThrows(CorruptIndexException.class,
|
||||
() -> CodecUtil.checksumEntireFile(input));
|
||||
assertEquals("misplaced codec footer (file truncated?): length=0 but footerLength==16 (resource=RAMInputStream(name=file))", e.getMessage());
|
||||
e = expectThrows(CorruptIndexException.class,
|
||||
() -> CodecUtil.retrieveChecksum(input));
|
||||
assertEquals("misplaced codec footer (file truncated?): length=0 but footerLength==16 (resource=RAMInputStream(name=file))", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue