FossifyOrg / Gallery

Browse your memories without any interruptions with this photo and video gallery
https://www.fossify.org
GNU General Public License v3.0
1.35k stars 40 forks source link

Renaming: if filename too long, file gets irrecoverably deleted without warning #129

Open GfEW opened 5 months ago

GfEW commented 5 months ago

Checklist

Affected app version

1.1.1

Affected Android/Custom ROM version

Android 9 to 11

Affected device model

diverse

How did you install the app?

F-Droid / IzzyOnDroid

Steps to reproduce the bug

I'm experiencing a severe, reproducible bug in Fossify Gallery 1.1.1 that unexpectedly deletes media files without warning.

I can be reproduced as follows:

  1. open Fossify Gallery
  2. navigate to any media file and tap to display it
  3. in the three-dots menu, tap "Rename"
  4. in the dialog field that opens, enter a new, very long filename.

Expected behavior

Fossify Gallery should either rename the file or, if the new name is too long, reject the invalid renaming operation, issue a brief explanation and leave the file intact.

Actual behavior

If the new filename happens to be too long (even if by just one character - there is no indication!), tapping "OK" will immediately DELETE the file, then merely informing you that "An unknown error occurred".

Screenshots/Screen recordings

No response

Additional information

Please note that the concerned file is not moved to Fossify Gallery's "Recycle Bin" nor to "Recovered", but fully removed from the file system.

Also note that this bug appears to be specific to Fossify Gallery (aside from Simple Gallery Pro): None of the three other gallery app or file managers I've tested on the same devices display this dangerous behaviour.

GfEW commented 5 months ago

@Aga-C re: niche

I agree this bug doesn't affect everyone - many users who tend to keep original filenames anyway, might never run into it.

However, it's certainly not overly exotic to use file names to be indicative of their respective contents, e. g. in documenting video recordings. If there are multiple aspects you want to be able to categorize or search those files for, filenames can get lengthy. But since Fossify Gallery fails to verify the input and also doesn't give any indication of remaining chars, it's dangerously easy to then run into this issue.

The severity of consequences in that case is very high, so I'd greatly appreciate if this bug didn't get buried.^^

A simple input length limitation to e. g. 200 chars would already do the trick. Thank you for considering! :-)

derei commented 3 months ago

Running GrapheneOS on Pixel 7Pro. Long filename doesn't seem to cause issues in my case.

Just a thought: is it possible that filename gets truncated and it ends up without extension, rather than being deleted? Gallery wouldn't show it, if it misses the extension, and it would appear as if it was deleted. Perhaps who encountered this issue could check the actual presence of a file with truncated name?

Long_filename
GfEW commented 3 months ago

Running GrapheneOS on Pixel 7Pro. Long filename doesn't seem to cause issues in my case.

The filename in your screenshot is less than 200 bytes long. In my tests, this bug is triggered if the new name (including extension) exceeds 255 bytes.

Here's a silly but illustrative example of a 255 B name, i. e. the maximum length allowed:

example of a 255 B filename

As soon as an attempt is made to add one more character to that name by renaming it in Fossify Gallery, the file vanishes from the system.

Just a thought: is it possible that filename gets truncated and it ends up without extension, rather than being deleted?

Filename extensions don't seem to matter for this bug, it occurs even if the new, long name entails multiple extensions. According to file managers I have checked for a file with the new name, as well as ls -l or find in termux, there is no such file (anywhere), neither with nor without extension.

That's no surprise since it's common for file systems to reject overly long filenames. The problem at hand isn't the length limitation imposed by the file system, but rather the way Fossify Gallery handles that limitation.

pkoepke commented 6 days ago

Adding a file that triggers this. I was trying to rename this file to Sick of people calling everything in crypto a Ponzi scheme. Some crypto projects are pump and dump schemes, while others are pyramid schemes. Others are just standard issue fraud. Others are just middlemen skimming of the top. Stop glossing over the diversity in the industry.. (I did not touch the Extension field, but it was png).

I'm aware that's a ridiculous filename but I sometimes copy and paste the whole text of a tweet for searching later.

If you remove the comma after 'pump and dump schemes' the issue doesn't happen. But I have experienced this with filenames without commas so I don't think commas are the issue.

I used another gallery app (https://f-droid.org/en/packages/deckers.thibault.aves.libre/) to rename the file using the string that triggered the issue and it worked with no problems.

Screenshot_20240711-060619