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

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


The following commit(s) were added to refs/heads/main by this push:
     new 7f01334403 Handle jackcess failures more robustly (#3208)
7f01334403 is described below

commit 7f01334403cdf049299b1984298d3df7c6bd5e82
Author: Tim Allison <[email protected]>
AuthorDate: Sat Sep 19 07:29:54 2026 -0400

    Handle jackcess failures more robustly (#3208)
---
 .../tika/parser/microsoft/JackcessParser.java      | 10 +--
 .../tika/parser/microsoft/JackcessCorruptTest.java | 74 ++++++++++++++++++++++
 2 files changed, 79 insertions(+), 5 deletions(-)

diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/JackcessParser.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/JackcessParser.java
index 20a7c542c9..96b77d5b53 100644
--- 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/JackcessParser.java
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/JackcessParser.java
@@ -30,7 +30,6 @@ import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
 import org.apache.tika.annotation.TikaComponent;
-import org.apache.tika.exception.CorruptedFileException;
 import org.apache.tika.exception.EncryptedDocumentException;
 import org.apache.tika.exception.TikaException;
 import org.apache.tika.exception.UnsupportedFormatException;
@@ -116,16 +115,17 @@ public class JackcessParser implements Parser {
             }
             throw e;
         } catch (IndexOutOfBoundsException e) {
-            // TIKA-4830
-            throw new CorruptedFileException(e.getMessage(), e);
+            // TIKA-4830. A TikaException, not CorruptedFileException: the 
latter aborts the
+            // whole container when the database is an embedded file.
+            throw new TikaException("Corrupt Access database: " + 
e.getMessage(), e);
         } catch (IllegalStateException e) {
             if (e.getMessage() != null) {
                 if (e.getMessage().contains("Incorrect password")) {
                     throw new EncryptedDocumentException(e);
                 }
                 if (e.getMessage().startsWith("invalid page number ")) {
-                    // TIKA-4830
-                    throw new CorruptedFileException(e.getMessage(), e);
+                    // TIKA-4830, as above
+                    throw new TikaException("Corrupt Access database: " + 
e.getMessage(), e);
                 }
             }
             throw e;
diff --git 
a/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/JackcessCorruptTest.java
 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/JackcessCorruptTest.java
new file mode 100644
index 0000000000..48813415e3
--- /dev/null
+++ 
b/tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/test/java/org/apache/tika/parser/microsoft/JackcessCorruptTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.microsoft;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.InputStream;
+import java.util.Arrays;
+
+import org.junit.jupiter.api.Test;
+import org.xml.sax.helpers.DefaultHandler;
+
+import org.apache.tika.TikaTest;
+import org.apache.tika.exception.CorruptedFileException;
+import org.apache.tika.exception.TikaException;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.ParseContext;
+
+/**
+ * A corrupt Access database must surface as a plain TikaException. 
CorruptedFileException is
+ * reserved for "stop everything": thrown by an embedded document it aborts 
the whole container,
+ * and a bad .mdb inside an archive must not cost the archive's remaining 
entries (TIKA-4830).
+ */
+public class JackcessCorruptTest extends TikaTest {
+
+    private byte[] original() throws Exception {
+        try (InputStream is = 
getResourceAsStream("/test-documents/testAccess2_2000.mdb")) {
+            return is.readAllBytes();
+        }
+    }
+
+    private void assertPlainTikaException(byte[] data) {
+        TikaException e = assertThrows(TikaException.class, () -> {
+            try (TikaInputStream tis = TikaInputStream.get(data)) {
+                new JackcessParser().parse(tis, new DefaultHandler(), new 
Metadata(),
+                        new ParseContext());
+            }
+        });
+        assertFalse(e instanceof CorruptedFileException, "must not abort a 
container: " + e);
+        assertTrue(e.getMessage().startsWith("Corrupt Access database"), 
e.getMessage());
+    }
+
+    @Test
+    public void indexOutOfBoundsBecomesTikaException() throws Exception {
+        // page pointers after the header page overwritten: Jackcess throws 
IndexOutOfBounds
+        byte[] data = original();
+        Arrays.fill(data, 4096 + 8, 4096 + 8 + 64, (byte) 0xff);
+        assertPlainTikaException(data);
+    }
+
+    @Test
+    public void invalidPageNumberBecomesTikaException() throws Exception {
+        // truncated to three pages: Jackcess throws 
IllegalStateException("invalid page number")
+        byte[] data = Arrays.copyOf(original(), 4096 * 3);
+        assertPlainTikaException(data);
+    }
+}

Reply via email to