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 2021/03/24 16:08:53 UTC

[tika] 03/04: TIKA-3335 -- invalid xml during encryption check shouldn't cause the parse to fail

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

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

commit ac05932ca0056e1871cbb15fa9d78277367dbe1f
Author: tallison <ta...@apache.org>
AuthorDate: Wed Mar 24 11:51:03 2021 -0400

    TIKA-3335 -- invalid xml during encryption check shouldn't cause the parse to fail
---
 .../org/apache/tika/parser/odf/OpenDocumentParser.java     | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tika-parsers/tika-parsers-classic/tika-parsers-classic-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/odf/OpenDocumentParser.java b/tika-parsers/tika-parsers-classic/tika-parsers-classic-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/odf/OpenDocumentParser.java
index 946e6de..bc00f57 100644
--- a/tika-parsers/tika-parsers-classic/tika-parsers-classic-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/odf/OpenDocumentParser.java
+++ b/tika-parsers/tika-parsers-classic/tika-parsers-classic-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/odf/OpenDocumentParser.java
@@ -336,10 +336,16 @@ public class OpenDocumentParser extends AbstractParser {
 
     private void checkForEncryption(InputStream stream, ParseContext context)
             throws SAXException, TikaException, IOException {
-        XMLReaderUtils.parseSAX(
-                new CloseShieldInputStream(stream),
-                new OfflineContentHandler(new EmbeddedContentHandler(
-                        new OpenDocumentManifestHandler())), context);
+        try {
+            XMLReaderUtils.parseSAX(new CloseShieldInputStream(stream),
+                    new OfflineContentHandler(new EmbeddedContentHandler(new OpenDocumentManifestHandler())), context);
+        } catch (SAXException e) {
+            if (e.getCause() != null
+                    && e.getCause() instanceof EncryptedDocumentException) {
+                throw (EncryptedDocumentException)e.getCause();
+            }
+            //otherwise...swallow
+        }
     }
 
     private boolean ignoreScriptFile(String embeddedName) {