simplify check if file is outside cache dir

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-11-21 11:53:02 +01:00
parent f1d03e235a
commit 19a69e0abf
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -98,12 +98,7 @@ object FileUtils {
fun copyFileToCache(context: Context, sourceFileUri: Uri, filename: String): File? {
val cachedFile = File(context.cacheDir, filename)
val aboveOrEqualAPI26Check =
!cachedFile.toPath().normalize().startsWith(context.cacheDir.toPath())
val isOutsideCacheDir = aboveOrEqualAPI26Check
if (isOutsideCacheDir) {
if (!cachedFile.toPath().normalize().startsWith(context.cacheDir.toPath())) {
Log.w(TAG, "cachedFile was not created in cacheDir. Aborting for security reasons.")
cachedFile.delete()
return null