CreateMode.REPLACE not respected on malformed input
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start at MediaStoreCompat.createDownload and reproduce the issue with a FileDescription name containing "?" and CreateMode.REPLACE, then inspect the returned storage file name. Determine the intended behavior when the OS renames malformed input; done means repeated calls no longer create "hello_(1)" unexpectedly, with the chosen behavior covered or documented.
Written by the indexing model from the issue text.
Description
CreateMode.REPLACE not respected on malformed input
When testing MediaStoreCompat.createDownload I found a bug caused by the OS renaming the name when it has invalid input.
Assume you have some regular function to create a file.
fun testDuplicate(context : Context) {
val file = MediaStoreCompat.createDownload(
context = context,
file = FileDescription(
name = "hello",
"test",
mimeType = "text/plain"
),
mode = CreateMode.REPLACE
)?.toStorageFile(context)
file?.openOutputStream()?.writer()?.use { writer ->
writer.write("Hello World!")
writer.flush()
}
}
This just creates a file named "hello.txt" with the content "Hello World!". And if called twice it replaces the file.
testDuplicate(context)
testDuplicate(context)
-> only 1 file
This is expected behavior, and everything is fine.
However if I now choose the name = "hello?" it creates the file fine, but the OS renames it to hello_, therefore the subsequent call to testDuplicate does not replace "hello_" because it is searching for "hello?" and therefore creates a new file called "hello_(1)".
The expected behavior is to either fail or replace the file named "hello_". However the current implementation creates another file even with the mode CreateMode.REPLACE.
This issue is fixed if the createDownload function also sanitized the file name like the os with e.g. .replace("?","_"), however I get that this is a wonky solution. I think it is sane to either document this as an issue, sanitize the filename, or even detect the creation of the wrong file name.
- Dominant language
- Kotlin
- Stars
- 867
- Forks
- 103
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from anggrayudi/SimpleStorage
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
anggrayudi/SimpleStorage#160 ·
-
bug unreproducible
Difficulty 4/5 3-5 days Newbie friendliness 30/100
anggrayudi/SimpleStorage#107 · 10 comments ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
anggrayudi/SimpleStorage#106 · 1 comment ·
-
bug wontfix
Difficulty 4/5 3-5 days Newbie friendliness 42/100
anggrayudi/SimpleStorage#103 · 7 comments ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 35/100
anggrayudi/SimpleStorage#94 · 8 comments ·
All issues in anggrayudi/SimpleStorage
Similar issues
-
:maddi-inspection-kotlin:test runs out of heap in a full maddi test run; exit 1 with no failing testOpenbuild/ci front-end:kotlin
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bisq-network/bisq-mobile#1948 ·
Maintainers usually reply within 1 day
-
afk-ok area:data-quality importer size:S
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
enorm-labs/event-junkie#3301 ·
Maintainers usually reply within 1 day
-
Negate special case for Long literals uses the wrong valuePossibly taken @bryantaustin13 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
cqframework/clinical_quality_language#1865 ·
Maintainers usually reply within 8 days
-
MDM: interfaceName cannot be set through managed configurationsPossibly taken @JulienUsson claimed this today. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 82/100
bk138/droidVNC-NG#404 · 1 comment ·