make SimpleText's checkIntegrity more robust so it's not fooled if you index the string END

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1662948 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2015-02-28 15:26:35 +00:00
parent eb8079c050
commit f5e8447d8c
1 changed files with 8 additions and 2 deletions

View File

@ -520,10 +520,16 @@ class SimpleTextDocValuesReader extends DocValuesProducer {
BytesRefBuilder scratch = new BytesRefBuilder();
IndexInput clone = data.clone();
clone.seek(0);
// checksum is fixed-width encoded with 20 bytes, plus 1 byte for newline (the space is included in SimpleTextUtil.CHECKSUM):
long footerStartPos = data.length() - (SimpleTextUtil.CHECKSUM.length + 21);
ChecksumIndexInput input = new BufferedChecksumIndexInput(clone);
while(true) {
while (true) {
SimpleTextUtil.readLine(input, scratch);
if (scratch.get().equals(END)) {
if (input.getFilePointer() >= footerStartPos) {
// Make sure we landed at precisely the right location:
if (input.getFilePointer() != footerStartPos) {
throw new CorruptIndexException("SimpleText failure: footer does not start at expected position current=" + input.getFilePointer() + " vs expected=" + footerStartPos, input);
}
SimpleTextUtil.checkFooter(input);
break;
}