FossifyOrg / Contacts

Easy and quick contact management with no ads, handles groups and favorites too.
https://www.fossify.org
GNU General Public License v3.0
269 stars 23 forks source link

[Bug] App crashes immediately after adding photo to contact, then refuses to open #38

Open tezrilet opened 7 months ago

tezrilet commented 7 months ago

Checklist

Describe the bug I am moving this issue over from SMT Contacts #1059, as I am now able to reproduce it consistently. The app will crash when saving a contact after adding a photo, then it is not able to open again. The issue seems to happen only with specific high-res photos. I'm not able to tell if it's due to the resolution, the file size, number of colors, or any other property.

I didn't want to experiment before in order to not lose my contacts, but since that app is no longer maintained, I will have to move on and recreate them. I haven't been able to access my contacts since November, so I wanted to test this issue first before committing to the new app.

To Reproduce (From a fresh installation) 1) Don't allow access to contacts permission 2) Tap the + icon to add a contact 3) Tap the camera icon to add a photo 4) Pick the "Choose photo" option (example photos below) 5) Use Fossify Gallery or Fossify File Manager to pick a photo 6) Complete action using Fossify Gallery 7) In the Editor, tap on the "Free" option to use the entire photo 8) Tap on the check mark to finish editing 9) Tap on the check mark to finish adding a contact

The app should immediately crash now. It will also keep crashing when attempting to open it. You can still access the settings from the App Info menu in the phone's settings via "Additional settings in the app", but certain options won't work. For example, enabling backups will crash. I tried to use that to salvage contacts from the old SMT app, but to no avail.

Example photos that cause a crash 1) I searched for a review of someone who has the same phone (Samsung Galaxy A52), and used the first example photo of theirs. 2) I also created a 4624x3468 image of random noise, and that also crashes the app.

Example photos that DO NOT cause a crash 1) I created a plain black 4624x3468 image in an image editor and saved it as a PNG and a JPG. Neither caused a crash. 2) I took a picture with my phone using the same settings as the one that was causing a crash, only this time I covered the lens to create a plain black image. This photo did not crash the app. 3) I tested to see if a higher resolution photo would cause a crash, using this picture (6720x4480 direct link), but that did not cause a crash. 4) I converted that same picture to PNG, in order to test if it was a file size issue. It created a 36 MB image, and that did not crash the app either.

Expected behavior The app should allow you to set any photo to a contact that you've taken with your phone, especially when in conjunction with Fossify Gallery, using any of the Editor features. If the app should crash due to low memory, or some kind of corruption, the app should make some attempt to save your data. It could either unset the photo, or dump a backup of the contacts to the home directory where it can be accessed by non-rooted phones. I'm not sure if resolution is the issue, but if so, an alternate could be to warn the user before using a high-res photo, or to automatically resize the photo to something more desirable.

Screenshots N/A

Device info (please complete the following information):

Additional context I would like to know if existing contacts are able to be saved after this issue occurs, or if it corrupts the app's storage somehow. I know that a pull request for a patch to SMT Contacts is out of scope, and would probably not be accepted, but I'd like some peace of mind to know if it really isn't possible to recover the old contacts.

Aga-C commented 7 months ago

I was able to reproduce it on an emulator. It looks that the problem is indeed in too large photo. Here's the crash log:

2024-01-23 21:58:13.805  6813-7530  SQLiteQuery             org.fossify.contacts.debug           E  exception: Row too big to fit into CursorWindow requiredPos=3, totalRows=4; query: SELECT * FROM contacts
2024-01-23 21:58:13.806  6813-7530  AndroidRuntime          org.fossify.contacts.debug           E  FATAL EXCEPTION: Thread-21
                                                                                                    Process: org.fossify.contacts.debug, PID: 6813
                                                                                                    android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=3, totalRows=4
                                                                                                        at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
                                                                                                        at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:1024)
                                                                                                        at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:838)
                                                                                                        at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
                                                                                                        at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:153)
                                                                                                        at android.database.sqlite.SQLiteCursor.onMove(SQLiteCursor.java:123)
                                                                                                        at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:255)
                                                                                                        at android.database.AbstractCursor.moveToNext(AbstractCursor.java:287)
                                                                                                        at org.fossify.commons.interfaces.ContactsDao_Impl.getContacts(ContactsDao_Impl.java:230)
                                                                                                        at org.fossify.commons.helpers.LocalContactsHelper.getAllContacts(LocalContactsHelper.kt:19)
                                                                                                        at org.fossify.commons.helpers.LocalContactsHelper.getAllContacts$default(LocalContactsHelper.kt:18)
                                                                                                        at org.fossify.commons.helpers.ContactsHelper$getContacts$1.invoke(ContactsHelper.kt:53)
                                                                                                        at org.fossify.commons.helpers.ContactsHelper$getContacts$1.invoke(ContactsHelper.kt:36)
                                                                                                        at org.fossify.commons.helpers.ConstantsKt.ensureBackgroundThread$lambda$0(Constants.kt:452)
                                                                                                        at org.fossify.commons.helpers.ConstantsKt.$r8$lambda$To1tc4xyXkXWhV8K0jRjmGoF1JY(Unknown Source:0)
                                                                                                        at org.fossify.commons.helpers.ConstantsKt$$ExternalSyntheticLambda0.run(Unknown Source:2)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)