Lucene - Core
  1. Lucene - Core
  2. LUCENE-5827

Make all Directory implementations correctly fail with IllegalArgumentException if slices are out of bounds

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.8, 4.9
    • Fix Version/s: 4.9.1, 4.10, 6.0
    • Component/s: core/store
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      After implementing LUCENE-5681, I noticed, that some directory implementations (like NIOFSDirectory) do not do bounds checks on slice creation. We should do this to early detect bugs, if file formats break because of index corrumption.

      This test in BaseDirectoryTestCase does not pass for all directory impls:

        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();    
        }
      
      1. LUCENE-5827.patch
        3 kB
        Uwe Schindler

        Issue Links

          Activity

          Hide
          Uwe Schindler added a comment -

          Simple patch. Test now passes.

          Show
          Uwe Schindler added a comment - Simple patch. Test now passes.
          Hide
          Michael McCandless added a comment -

          Reopen for backport to 4.9.1...

          Show
          Michael McCandless added a comment - Reopen for backport to 4.9.1...
          Hide
          ASF subversion and git services added a comment -

          Commit 1625422 from Michael McCandless in branch 'dev/branches/lucene_solr_4_9'
          [ https://svn.apache.org/r1625422 ]

          LUCENE-5827: backport to 4.9.x

          Show
          ASF subversion and git services added a comment - Commit 1625422 from Michael McCandless in branch 'dev/branches/lucene_solr_4_9' [ https://svn.apache.org/r1625422 ] LUCENE-5827 : backport to 4.9.x
          Hide
          Michael McCandless added a comment -

          Bulk close for Lucene/Solr 4.9.1 release

          Show
          Michael McCandless added a comment - Bulk close for Lucene/Solr 4.9.1 release

            People

            • Assignee:
              Uwe Schindler
              Reporter:
              Uwe Schindler
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development