From 17732a0edce1de175ffa004765dcaf94858c3bb1 Mon Sep 17 00:00:00 2001 From: guitarooman14 Date: Wed, 5 Feb 2025 01:53:18 +0100 Subject: [PATCH] fix(filesystem): unexpected error when saving file lead to crashing the app --- .../com/capacitorjs/plugins/filesystem/Filesystem.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/filesystem/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java b/filesystem/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java index c3fb54b44..402194184 100644 --- a/filesystem/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java +++ b/filesystem/android/src/main/java/com/capacitorjs/plugins/filesystem/Filesystem.java @@ -61,7 +61,12 @@ public void saveFile(File file, String data, Charset charset, Boolean append) th } else { //remove header from dataURL if (data.contains(",")) { - data = data.split(",")[1]; + String[] tmp = data.split(","); + if (tmp.length > 1) { + data = tmp[1]; + } else { + throw new IllegalArgumentException("The supplied data is not valid base64 content."); + } } FileOutputStream fos = new FileOutputStream(file, append); fos.write(Base64.decode(data, Base64.NO_WRAP));