You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by gs...@apache.org on 2013/08/08 22:07:19 UTC

svn commit: r1512011 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/store/NIOFSDirectory.java core/src/java/org/apache/lucene/store/SimpleFSDirectory.java

Author: gsingers
Date: Thu Aug  8 20:07:18 2013
New Revision: 1512011

URL: http://svn.apache.org/r1512011
Log:
LUCENE-5160: check for -1 return conditions in file reads

Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1512011&r1=1512010&r2=1512011&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Thu Aug  8 20:07:18 2013
@@ -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

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java?rev=1512011&r1=1512010&r2=1512011&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java Thu Aug  8 20:07:18 2013
@@ -200,6 +200,9 @@ public class NIOFSDirectory extends FSDi
           }
           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;

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java?rev=1512011&r1=1512010&r2=1512011&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java Thu Aug  8 20:07:18 2013
@@ -155,6 +155,9 @@ public class SimpleFSDirectory extends F
               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) {