lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1610944 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/store/ lucene/test-framework/ lucene/test-framework/src/java/org/apache/lucene/store/
Date Wed, 16 Jul 2014 09:03:49 GMT
Author: uschindler
Date: Wed Jul 16 09:03:49 2014
New Revision: 1610944

URL: http://svn.apache.org/r1610944
Log:
Merged revision(s) 1610943 from lucene/dev/trunk:
LUCENE-5827: Make all Directory implementations correctly fail with IllegalArgumentException
if slices are out of bounds

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
    lucene/dev/branches/branch_4x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1610944&r1=1610943&r2=1610944&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Wed Jul 16 09:03:49 2014
@@ -85,6 +85,9 @@ Bug Fixes
 
 * LUCENE-5824: Fix hunspell 'long' flag handling. (Robert Muir)
 
+* LUCENE-5827: Make all Directory implementations correctly fail with
+  IllegalArgumentException if slices are out of bounds.  (Uwe SChindler)
+
 Test Framework
 
 * LUCENE-5786: Unflushed/ truncated events file (hung testing subprocess).

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java?rev=1610944&r1=1610943&r2=1610944&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java
Wed Jul 16 09:03:49 2014
@@ -133,6 +133,9 @@ public class NIOFSDirectory extends FSDi
     
     @Override
     public IndexInput slice(String sliceDescription, long offset, long length) throws IOException
{
+      if (offset < 0 || length < 0 || offset + length > this.length()) {
+        throw new IllegalArgumentException("slice() " + sliceDescription + " out of bounds:
"  + this);
+      }
       return new NIOFSIndexInput(sliceDescription, channel, off + offset, length, getBufferSize());
     }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java?rev=1610944&r1=1610943&r2=1610944&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/SimpleFSDirectory.java
Wed Jul 16 09:03:49 2014
@@ -110,6 +110,9 @@ public class SimpleFSDirectory extends F
     
     @Override
     public IndexInput slice(String sliceDescription, long offset, long length) throws IOException
{
+      if (offset < 0 || length < 0 || offset + length > this.length()) {
+        throw new IllegalArgumentException("slice() " + sliceDescription + " out of bounds:
"  + this);
+      }
       return new SimpleFSIndexInput(sliceDescription, file, off + offset, length, getBufferSize());
     }
 

Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java?rev=1610944&r1=1610943&r2=1610944&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
Wed Jul 16 09:03:49 2014
@@ -459,6 +459,37 @@ public abstract class BaseDirectoryTestC
     dir.close();
   }
 
+  public void testSliceOutOfBounds() throws Exception {
+    Directory dir = getDirectory(createTempDir("testSliceOutOfBounds"));
+    IndexOutput o = dir.createOutput("out", newIOContext(random()));
+    final int len = random().nextInt(2040) + 8;
+    byte[] b = new byte[len];
+    o.writeBytes(b, 0, len);
+    o.close();
+    IndexInput i = dir.openInput("out", newIOContext(random()));
+    try {
+      i.slice("slice1", 0, len + 1);
+      fail("Did not get IllegalArgumentException");
+    } catch (IllegalArgumentException iae) {
+      // pass
+    }
+    try {
+      i.slice("slice2", -1, len);
+      fail("Did not get IllegalArgumentException");
+    } catch (IllegalArgumentException iae) {
+      // pass
+    }
+    IndexInput slice = i.slice("slice3", 4, len / 2);
+    try {
+      slice.slice("slice3sub", 1, len / 2);
+      fail("Did not get IllegalArgumentException");
+    } catch (IllegalArgumentException iae) {
+      // pass
+    }
+    i.close();
+    dir.close();    
+  }
+  
   // LUCENE-3382 -- make sure we get exception if the directory really does not exist.
   public void testNoDir() throws Throwable {
     File tempDir = createTempDir("doesnotexist");



Mime
View raw message