mirror of https://github.com/apache/lucene.git
LUCENE-5160: check for -1 return conditions in file reads
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1512011 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3231e204c4
commit
8177498c86
|
@ -46,6 +46,12 @@ New Features
|
|||
* SOLR-3359: Added analyzer attribute/property to SynonymFilterFactory.
|
||||
(Ryo Onodera via Koji Sekiguchi)
|
||||
|
||||
Bugs
|
||||
|
||||
* LUCENE-5160: Handle the case where reading from a file or FileChannel returns -1, which
|
||||
could happen in rare cases where something happens to the file between the time we start the
|
||||
read loop (where we check the length) and when we actually do the read. (gsingers, yonik, Robert Muir, Uwe Schindler)
|
||||
|
||||
Optimizations
|
||||
|
||||
* LUCENE-4848: Use Java 7 NIO2-FileChannel instead of RandomAccessFile
|
||||
|
|
|
@ -200,6 +200,9 @@ public class NIOFSDirectory extends FSDirectory {
|
|||
}
|
||||
bb.limit(limit);
|
||||
int i = channel.read(bb, pos);
|
||||
if (i < 0){//be defensive here, even though we checked before hand, something could have changed
|
||||
throw new EOFException("read past EOF: " + this + " off: " + offset + " len: " + len + " pos: " + pos + " limit: " + limit + " end: " + end);
|
||||
}
|
||||
pos += i;
|
||||
readOffset += i;
|
||||
readLength -= i;
|
||||
|
|
|
@ -155,6 +155,9 @@ public class SimpleFSDirectory extends FSDirectory {
|
|||
readLength = chunkSize;
|
||||
}
|
||||
final int i = file.read(b, offset + total, readLength);
|
||||
if (i < 0){//be defensive here, even though we checked before hand, something could have changed
|
||||
throw new EOFException("read past EOF: " + this + " off: " + offset + " len: " + len + " total: " + total + " readLen: " + readLength + " end: " + end);
|
||||
}
|
||||
total += i;
|
||||
} while (total < len);
|
||||
} catch (OutOfMemoryError e) {
|
||||
|
|
Loading…
Reference in New Issue