From 072e05c111c461d925f56842d53d1a58970d04f2 Mon Sep 17 00:00:00 2001 From: chagaiB Date: Tue, 16 Sep 2025 23:21:39 +0300 Subject: [PATCH 1/2] Update FileStorageUtils.java Fix crash when decoding filenames with invalid % characters Signed-off-by: chagaiB --- .../owncloud/android/utils/FileStorageUtils.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java b/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java index 550b0e855e21..38df1fdea912 100644 --- a/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java @@ -73,13 +73,24 @@ public final class FileStorageUtils { private FileStorageUtils() { // utility class -> private constructor } + // Safely decodes URLs without crashing on '%' patterns + private static String safeUrlDecode(String s){ + try{ + return java.net.URLDecoder.decode(s, StandardCharsets.UTF_8.name()); + } + catch (IllegalArgumentException e){ + // If the text has invalid % sequences (like "65% on ..."), return as-is + return s; + } + } + public static boolean containsBidiControlCharacters(String filename) { if (filename == null) return false; String decoded; try { - decoded = URLDecoder.decode(filename, StandardCharsets.UTF_8.toString()); + decoded = safeUrlDecode(filename); } catch (UnsupportedEncodingException e) { return false; } From 48b1ee17c74483012a6ae66e9b63bae47b9feab3 Mon Sep 17 00:00:00 2001 From: chagaiB Date: Tue, 16 Sep 2025 23:35:42 +0300 Subject: [PATCH 2/2] Fix crash when decoding filenames with invalid % characters This commit adds a safeUrlDecode() helper that prevents IllegalArgumentException when filenames contain invalid % patterns (like "65% on Sonic Wave"). Instead of crashing, the filename is returned as-is and the app continues normally. Signed-off-by: chagaiB --- .../android/utils/FileStorageUtils.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java b/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java index 38df1fdea912..88dbb071138b 100644 --- a/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java +++ b/app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java @@ -74,13 +74,13 @@ private FileStorageUtils() { // utility class -> private constructor } // Safely decodes URLs without crashing on '%' patterns - private static String safeUrlDecode(String s){ + private static String safeUrlDecode(String filename){ try{ - return java.net.URLDecoder.decode(s, StandardCharsets.UTF_8.name()); + return java.net.URLDecoder.decode(filename, StandardCharsets.UTF_8.name()); } - catch (IllegalArgumentException e){ + catch (IllegalArgumentException ignored){ // If the text has invalid % sequences (like "65% on ..."), return as-is - return s; + return filename; } } @@ -88,13 +88,9 @@ private static String safeUrlDecode(String s){ public static boolean containsBidiControlCharacters(String filename) { if (filename == null) return false; - String decoded; - try { - decoded = safeUrlDecode(filename); - } catch (UnsupportedEncodingException e) { - return false; - } - + String decoded; + decoded = safeUrlDecode(filename); + int[] bidiControlCharacters = { 0x202A, 0x202B, 0x202C, 0x202D, 0x202E, 0x200E, 0x200F, 0x2066, 0x2067, 0x2068,