oxen-io / session-android

A private messenger for Android.
https://getsession.org
GNU General Public License v3.0
1.83k stars 170 forks source link

App crashes when saving lots of images #1296

Open Cinj216 opened 1 year ago

Cinj216 commented 1 year ago

Through a lot of testing and experimentation, I've determined that there is an error in the way the app handles filename conflicts. Quite often it will correctly rename files so you end up with, for example, "image (1).jpg, "image (2).jpg", "image (3).jpg", and so on. But in many instances, it will fail to do so and the app will crash, leaving a file named ".pending-(some numbers)-image.(whatever extension)" that didn't get it's rename completed. The more images you are trying to save at once, the better the odds of it happening, although I have observed it happening with a mere 2-3 files. Saving images individually never seems to invoke this bug.

A workaround has been to continually save in small batches, then move the files from the /pictures/ folder somewhere else before saving the next batch to minimize the potential conflicts. This, however, proves tedious and doesn't always stop the bug from striking, with some files being more of a problem than others for reasons I haven't been able to figure out.

I've also observed that when files are saved individually, they are automatically given a name in the order of "session-(timestamp).(ext)", but for whatever reason are saved under the same name they were uploaded under if saved in bulk. Seems odd that they are not given this rename treatment under a condition that would be more beneficial. However, there's not enough granularity in the timestamp to prevent conflicts still since it only goes down to the second.

An alternative could be an option for the user to have the app cache the files in a fashion where the user would have direct access to them as opposed to whatever obfuscation method is currently employed.

Thanks for your time.

hjubb commented 1 year ago

Hmm, I didn't realise that you could save multiple at a time, but I guess that makes sense. It might just be trying to do them all at once and running into memory issues, could probably look at just doing them sequentially if it's working how I think it might be (it might take a little longer but shouldn't crash I guess)

tashijayla commented 1 year ago

@hjubb if you click on the gallery icon from inside the Session android app and hold on a picture it's possible to select as many pictures as you like' ready to send, once they have been sent both chat recipients have the ability to save all the pictures with one button which is just under the emoji reacts interface

Cinj216 commented 1 year ago

Actually, you can hit the three dots in the upper right corner of a group and choose "all media" and from there select multiple files that have been posted to save or delete.

Anyhow, through my expensive experimentation on working around this issue I finally discovered the specific cause. If the program has to incrementally rename files due to a filename collision, there appears to be an upper limit of 31. The moment there is a file that, for example, is named "image (31)" and a pending rename would require that the next file have the number 32 appended, the program will crash.

tashijayla commented 1 year ago

@Cinj216 thank you I didn't know it was possible to save media that way as well