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 a44588a35a TIKA-4808 - guard TikaCLI arg-validation file checks 
against InvalidPathException (#3035)
a44588a35a is described below

commit a44588a35ac0ee0b343acd086504da2da391dd35
Author: Tim Allison <[email protected]>
AuthorDate: Mon Aug 17 14:37:16 2026 -0400

    TIKA-4808 - guard TikaCLI arg-validation file checks against 
InvalidPathException (#3035)
---
 .../src/main/java/org/apache/tika/cli/TikaCLI.java | 29 +++++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java 
b/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
index d253ec0b24..c6a31730e7 100644
--- a/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
+++ b/tika-app/src/main/java/org/apache/tika/cli/TikaCLI.java
@@ -35,6 +35,7 @@ import java.lang.reflect.Field;
 import java.net.URI;
 import java.net.URL;
 import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
@@ -615,7 +616,7 @@ public class TikaCLI {
             // surface as a confusing MalformedURLException. Catch 
dash-prefixed
             // args that aren't the stdin marker or an existing file and emit
             // an actionable error before that happens.
-            if (arg.startsWith("-") && !arg.equals("-") && !new 
File(arg).exists()) {
+            if (arg.startsWith("-") && !arg.equals("-") && !fileExists(arg)) {
                 String hint = " Run with --help for the full option list.";
                 // Heuristic: single-dash + multi-letter (e.g. "-input") is
                 // usually a long-form-with-one-dash typo. Single-dash + one
@@ -639,9 +640,8 @@ public class TikaCLI {
                 }
             } else {
                 URL url;
-                File file = new File(arg);
-                if (file.isFile()) {
-                    url = file
+                if (isRegularFile(arg)) {
+                    url = new File(arg)
                             .toURI()
                             .toURL();
                 } else {
@@ -666,6 +666,27 @@ public class TikaCLI {
         }
     }
 
+    /**
+     * Windows rejects a colon outside the drive-letter slot (e.g. a URL passed
+     * as a raw CLI arg) by throwing InvalidPathException from File I/O instead
+     * of just reporting "not found"; normalize that to "doesn't exist".
+     */
+    private static boolean fileExists(String arg) {
+        try {
+            return new File(arg).exists();
+        } catch (InvalidPathException e) {
+            return false;
+        }
+    }
+
+    private static boolean isRegularFile(String arg) {
+        try {
+            return new File(arg).isFile();
+        } catch (InvalidPathException e) {
+            return false;
+        }
+    }
+
     //TODO -- rework with json serialization
     /*private void dumpConfig(TikaConfigSerializer.Mode mode) throws Exception 
{
         configure();

Reply via email to