mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Merge pull request #3064 from TR-SLimey/fix-path-traversal-file-save-api29
When downloading a file in <= API 29, replace dangerous characters with underscores
This commit is contained in:
commit
5c89179c47
1 changed files with 4 additions and 1 deletions
|
@ -514,7 +514,7 @@ fun selectTxtFileToWrite(
|
|||
@Suppress("DEPRECATION")
|
||||
fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: String?): File? {
|
||||
// defines another name for the external media
|
||||
val dstFileName: String
|
||||
var dstFileName: String
|
||||
|
||||
// build a filename is not provided
|
||||
if (null == outputFilename) {
|
||||
|
@ -529,6 +529,9 @@ fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: Strin
|
|||
dstFileName = outputFilename
|
||||
}
|
||||
|
||||
// remove dangerous characters from the filename
|
||||
dstFileName = dstFileName.replace(Regex("""[/\\]"""), "_")
|
||||
|
||||
var dstFile = File(dstDirPath, dstFileName)
|
||||
|
||||
// if the file already exists, append a marker
|
||||
|
|
Loading…
Reference in a new issue