Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust cacheDir based on Android version #4356

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/src/main/java/com/nextcloud/talk/utils/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import android.content.ContentResolver
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.provider.OpenableColumns
import android.util.Log
import java.io.File
Expand Down Expand Up @@ -115,7 +116,17 @@ object FileUtils {
fun copyFileToCache(context: Context, sourceFileUri: Uri, filename: String): File? {
val cachedFile = File(context.cacheDir, filename)

if (!cachedFile.canonicalPath.startsWith(context.cacheDir.canonicalPath, true)) {
val aboveOrEqualAPI26Check =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
!cachedFile.toPath().normalize().startsWith(context.cacheDir.toPath())

val belowAPI26Check =
Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
!cachedFile.canonicalPath.startsWith(context.cacheDir.canonicalPath, true)

val isOutsideCacheDir = aboveOrEqualAPI26Check || belowAPI26Check

if (isOutsideCacheDir) {
Log.w(TAG, "cachedFile was not created in cacheDir. Aborting for security reasons.")
cachedFile.delete()
return null
Expand Down
Loading