You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2019/07/25 00:38:52 UTC

[tika] branch master updated: prep for 1.22

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/master by this push:
     new 1158d89  prep for 1.22
1158d89 is described below

commit 1158d893dc952c573f7a12c7e4855cdce479fc2a
Author: TALLISON <ta...@apache.org>
AuthorDate: Wed Jul 24 20:38:36 2019 -0400

    prep for 1.22
---
 LICENSE.txt                                        |  26 ++++++++++++++++++++-
 .../sax/AbstractRecursiveParserWrapperHandler.java |   9 +++++++
 .../tika/parser/pkg/CompressorParserTest.java      |  11 +++++++++
 .../org/apache/tika/parser/pkg/ZipParserTest.java  |  13 +++++++++++
 .../test/resources/test-documents/testGZ_quine.gz  | Bin 0 -> 204 bytes
 5 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/LICENSE.txt b/LICENSE.txt
index 150b1d9..7b0246e 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -412,4 +412,28 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
\ No newline at end of file
+THE SOFTWARE.
+
+----------------------------------------------
+testGZ_quine.gz test file (MIT License)
+https://twitter.com/WhoStoleHonno/status/1153315367235784704?s=20
+
+Copyright (c) 2019 by Matthew Barber.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/tika-core/src/main/java/org/apache/tika/sax/AbstractRecursiveParserWrapperHandler.java b/tika-core/src/main/java/org/apache/tika/sax/AbstractRecursiveParserWrapperHandler.java
index 55f5c58..8bdba65 100644
--- a/tika-core/src/main/java/org/apache/tika/sax/AbstractRecursiveParserWrapperHandler.java
+++ b/tika-core/src/main/java/org/apache/tika/sax/AbstractRecursiveParserWrapperHandler.java
@@ -52,8 +52,12 @@ public abstract class AbstractRecursiveParserWrapperHandler extends DefaultHandl
             Property.internalText(TikaCoreProperties.TIKA_META_PREFIX+"embedded_resource_path");
 
     private final ContentHandlerFactory contentHandlerFactory;
+
+    private static final int MAX_DEPTH = 100;
+
     private final int maxEmbeddedResources;
     private int embeddedResources = 0;
+    private int embeddedDepth = 0;
 
     public AbstractRecursiveParserWrapperHandler(ContentHandlerFactory contentHandlerFactory) {
         this(contentHandlerFactory, -1);
@@ -82,6 +86,10 @@ public abstract class AbstractRecursiveParserWrapperHandler extends DefaultHandl
      */
     public void startEmbeddedDocument(ContentHandler contentHandler, Metadata metadata) throws SAXException {
         embeddedResources++;
+        embeddedDepth++;
+        if (embeddedDepth >= MAX_DEPTH) {
+            throw new SAXException("Max embedded depth reached: "+embeddedDepth);
+        }
     }
     /**
      * This is called after parsing each embedded document.  Override this
@@ -92,6 +100,7 @@ public abstract class AbstractRecursiveParserWrapperHandler extends DefaultHandl
      * @throws SAXException
      */
     public void endEmbeddedDocument(ContentHandler contentHandler, Metadata metadata) throws SAXException {
+        embeddedDepth--;
     }
 
     /**
diff --git a/tika-parsers/src/test/java/org/apache/tika/parser/pkg/CompressorParserTest.java b/tika-parsers/src/test/java/org/apache/tika/parser/pkg/CompressorParserTest.java
index 47919e9..ccb8a5b 100644
--- a/tika-parsers/src/test/java/org/apache/tika/parser/pkg/CompressorParserTest.java
+++ b/tika-parsers/src/test/java/org/apache/tika/parser/pkg/CompressorParserTest.java
@@ -35,6 +35,7 @@ import java.util.Set;
 
 import org.apache.commons.compress.compressors.CompressorStreamFactory;
 import org.apache.tika.TikaTest;
+import org.apache.tika.exception.TikaException;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.metadata.TikaCoreProperties;
 import org.apache.tika.mime.MediaType;
@@ -112,4 +113,14 @@ public class CompressorParserTest extends TikaTest {
             }
         }
     }
+
+    @Test(expected = TikaException.class)
+    public void testQuineXHTML() throws Exception {
+        getXML("testGZ_quine.gz");
+    }
+
+    @Test
+    public void testQuineRecursive() throws Exception {
+        getRecursiveMetadata("testGZ_quine.gz");
+    }
 }
diff --git a/tika-parsers/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java b/tika-parsers/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java
index ae7eb96..ed99f9e 100644
--- a/tika-parsers/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java
+++ b/tika-parsers/src/test/java/org/apache/tika/parser/pkg/ZipParserTest.java
@@ -227,5 +227,18 @@ public class ZipParserTest extends AbstractPkgTest {
         List<Metadata> metadataList = getRecursiveMetadata("testJAR.jar");
         assertEquals("application/java-archive", metadataList.get(0).get(HttpHeaders.CONTENT_TYPE));
     }
+/*
+    If we can get permission to add http://alf.nu/s/droste.zip
+    we can turn these tests on.
 
+    @Test
+    public void testQuineRecursiveParserWrapper() throws Exception {
+        debug(getRecursiveMetadata("testZIP_quine.zip"));
+    }
+
+    @Test(expected = TikaException.class)
+    public void testQuine() throws Exception {
+        getXML("testZIP_quine.zip");
+    }
+*/
 }
diff --git a/tika-parsers/src/test/resources/test-documents/testGZ_quine.gz b/tika-parsers/src/test/resources/test-documents/testGZ_quine.gz
new file mode 100644
index 0000000..67b41ba
Binary files /dev/null and b/tika-parsers/src/test/resources/test-documents/testGZ_quine.gz differ