You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2017/05/16 16:33:14 UTC

[1/2] lucene-solr:master: LUCENE-7831: CodecUtil should not seek to negative offsets.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 2dadd84fc -> 02490e309
  refs/heads/master 851678388 -> 9e1fcb0eb


LUCENE-7831: CodecUtil should not seek to negative offsets.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/9e1fcb0e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/9e1fcb0e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/9e1fcb0e

Branch: refs/heads/master
Commit: 9e1fcb0eb47637082d15700a92e52f0b1c155bc7
Parents: 8516783
Author: Adrien Grand <jp...@gmail.com>
Authored: Tue May 16 18:31:57 2017 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Tue May 16 18:31:57 2017 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                     |  5 ++++-
 .../src/java/org/apache/lucene/codecs/CodecUtil.java   |  6 ++++++
 .../test/org/apache/lucene/codecs/TestCodecUtil.java   | 13 +++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9e1fcb0e/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index bbdc7bd..ce6ba67 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -93,7 +93,10 @@ Other
   (Daniel Jelinski via Adrien Grand)
 
 ======================= Lucene 6.7.0 =======================
-(No Changes)
+
+Bug Fixes
+
+* LUCENE-7831: CodecUtil should not seek to negative offsets. (Adrien Grand)
 
 ======================= Lucene 6.6.0 =======================
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9e1fcb0e/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java b/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
index a625b47..c49946b 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
@@ -331,6 +331,9 @@ public final class CodecUtil {
   /** Retrieves the full footer from the provided {@link IndexInput}.  This throws
    *  {@link CorruptIndexException} if this file does not have a valid footer. */
   public static byte[] readFooter(IndexInput in) throws IOException {
+    if (in.length() < footerLength()) {
+      throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), in);
+    }
     in.seek(in.length() - footerLength());
     validateFooter(in);
     in.seek(in.length() - footerLength());
@@ -516,6 +519,9 @@ public final class CodecUtil {
     clone.seek(0);
     ChecksumIndexInput in = new BufferedChecksumIndexInput(clone);
     assert in.getFilePointer() == 0;
+    if (in.length() < footerLength()) {
+      throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), input);
+    }
     in.seek(in.length() - footerLength());
     return checkFooter(in);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/9e1fcb0e/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
index d403f81..0ff7f7c 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
@@ -303,4 +303,17 @@ public class TestCodecUtil extends LuceneTestCase {
     fakeChecksum.set((1L << 32) - 1); // ok
     CodecUtil.writeCRC(fakeOutput);
   }
+
+  public void testTruncatedFileThrowsCorruptIndexException() throws IOException {
+    RAMFile file = new RAMFile();
+    IndexOutput output = new RAMOutputStream(file, false);
+    output.close();
+    IndexInput input = new RAMInputStream("file", file);
+    CorruptIndexException e = expectThrows(CorruptIndexException.class,
+        () -> CodecUtil.checksumEntireFile(input));
+    assertEquals("misplaced codec footer (file truncated?): length=0 but footerLength==16 (resource=RAMInputStream(name=file))", e.getMessage());
+    e = expectThrows(CorruptIndexException.class,
+        () -> CodecUtil.retrieveChecksum(input));
+    assertEquals("misplaced codec footer (file truncated?): length=0 but footerLength==16 (resource=RAMInputStream(name=file))", e.getMessage());
+  }
 }


[2/2] lucene-solr:branch_6x: LUCENE-7831: CodecUtil should not seek to negative offsets.

Posted by jp...@apache.org.
LUCENE-7831: CodecUtil should not seek to negative offsets.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/02490e30
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/02490e30
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/02490e30

Branch: refs/heads/branch_6x
Commit: 02490e30910c5f805f5b1df8320582a42212cb85
Parents: 2dadd84
Author: Adrien Grand <jp...@gmail.com>
Authored: Tue May 16 18:31:57 2017 +0200
Committer: Adrien Grand <jp...@gmail.com>
Committed: Tue May 16 18:32:21 2017 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                                     |  5 ++++-
 .../src/java/org/apache/lucene/codecs/CodecUtil.java   |  6 ++++++
 .../test/org/apache/lucene/codecs/TestCodecUtil.java   | 13 +++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/02490e30/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3bbe1f1..77d5e08 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -4,7 +4,10 @@ For more information on past and future Lucene versions, please see:
 http://s.apache.org/luceneversions
 
 ======================= Lucene 6.7.0 =======================
-(No Changes)
+
+Bug Fixes
+
+* LUCENE-7831: CodecUtil should not seek to negative offsets. (Adrien Grand)
 
 ======================= Lucene 6.6.0 =======================
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/02490e30/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java b/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
index a625b47..c49946b 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
@@ -331,6 +331,9 @@ public final class CodecUtil {
   /** Retrieves the full footer from the provided {@link IndexInput}.  This throws
    *  {@link CorruptIndexException} if this file does not have a valid footer. */
   public static byte[] readFooter(IndexInput in) throws IOException {
+    if (in.length() < footerLength()) {
+      throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), in);
+    }
     in.seek(in.length() - footerLength());
     validateFooter(in);
     in.seek(in.length() - footerLength());
@@ -516,6 +519,9 @@ public final class CodecUtil {
     clone.seek(0);
     ChecksumIndexInput in = new BufferedChecksumIndexInput(clone);
     assert in.getFilePointer() == 0;
+    if (in.length() < footerLength()) {
+      throw new CorruptIndexException("misplaced codec footer (file truncated?): length=" + in.length() + " but footerLength==" + footerLength(), input);
+    }
     in.seek(in.length() - footerLength());
     return checkFooter(in);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/02490e30/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
index d403f81..0ff7f7c 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
@@ -303,4 +303,17 @@ public class TestCodecUtil extends LuceneTestCase {
     fakeChecksum.set((1L << 32) - 1); // ok
     CodecUtil.writeCRC(fakeOutput);
   }
+
+  public void testTruncatedFileThrowsCorruptIndexException() throws IOException {
+    RAMFile file = new RAMFile();
+    IndexOutput output = new RAMOutputStream(file, false);
+    output.close();
+    IndexInput input = new RAMInputStream("file", file);
+    CorruptIndexException e = expectThrows(CorruptIndexException.class,
+        () -> CodecUtil.checksumEntireFile(input));
+    assertEquals("misplaced codec footer (file truncated?): length=0 but footerLength==16 (resource=RAMInputStream(name=file))", e.getMessage());
+    e = expectThrows(CorruptIndexException.class,
+        () -> CodecUtil.retrieveChecksum(input));
+    assertEquals("misplaced codec footer (file truncated?): length=0 but footerLength==16 (resource=RAMInputStream(name=file))", e.getMessage());
+  }
 }