Bug #4782

v3.2 detachThread crash

Added by n8fr8 almost 3 years ago. Updated almost 3 years ago.

Status:NewStart date:03/23/2015
Priority:NormalDue date:
Assignee:hans% Done:

0%

Category:-
Target version:0.3.1
Component:

Description

after a few times calling

03-23 17:11:39.550: W/libsqlfs(22829): library routine called out of sequence
03-23 17:11:39.550: A/libc(22829): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xc in tid 22947 (AsyncTask #5)
03-23 17:11:39.577: A/libc(22829): heap corruption detected by tmalloc_large
03-23 17:11:39.577: A/libc(22829): Fatal signal 6 (SIGABRT), code -6 in tid 22829 (iocipher.camera)

class BitmapWorkerTask extends AsyncTask<File, Void, Bitmap> {

// Decode image in background.
@Override
protected Bitmap doInBackground(File... fileImage) {
BitmapFactory.Options bounds = new BitmapFactory.Options();        
bounds.inSampleSize = 8;
Bitmap b;
try {
FileInputStream fis = new FileInputStream(fileImage[0]);
b = BitmapFactory.decodeStream(fis, null, bounds);
fis.close();
mBitCache.put(fileImage[0].getAbsolutePath(), b);
VirtualFileSystem.get().detachThread();
return b;
} catch (Exception e) {
Log.e(TAG,"error decoding bitmap preview",e);
}
VirtualFileSystem.get().detachThread();
return null;
}
// Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null)
((IconicList)gridview.getAdapter()).notifyDataSetChanged();
}
}

IOCipher-v0.3-3-ga3cf8cd.zip.sig (543 Bytes) hans, 03/24/2015 09:46 pm

IOCipher-v0.3-3-ga3cf8cd.zip (4.34 MB) hans, 03/24/2015 09:46 pm

History

#1 Updated by n8fr8 almost 3 years ago

it always seems to happen the 5th time it is called (detach)

#2 Updated by hans almost 3 years ago

This looks pretty complicated. On my device, it crashes loading the third of 6 images in the gallery. The message "Library routine called out of sequence" is the key part, its from SQLite3:

Sometimes a thread is fully detached and the sqlfs_t is dealloced. But sometimes the sqlfs_t gets reused, then it crashes when trying to sqlite3_close() that SQLite connection, which probably means the db connection was either not open yet, or already closed.

sqlfs_t_init FIRST_SQLFS_T sqlite3_open complete: FIRST_DB

sqlfs_t_init SECOND_SQLFS_T sqlite3_open complete: SECOND_DB
sqlfs_detach_thread 0x20
sqlfs_t_finalize SECOND_SQLFS_T
sqlfs_t_finalize SECOND_SQLFS_T sqlite3_close SECOND_DB

sqlfs_t_init THIRD_SQLFS_T sqlite3_open complete: THIRD_DB
sqlfs_detach_thread 0x20
sqlfs_t_finalize THIRD_SQLFS_T
sqlfs_t_finalize THIRD_SQLFS_T sqlite3_close THIRD_DB

sqlfs_t_init THIRD_SQLFS_T sqlite3_open complete: FOURTH_DB
sqlfs_detach_thread 0x20
sqlfs_t_finalize THIRD_SQLFS_T
sqlfs_t_finalize THIRD_SQLFS_T sqlite3_close FOURTH_DB
library routine called out of sequence

I attached a version of IOCipher with more debugging if you want to try something. The short term workaround is to handle all IOCipher operations in a single thread where the actions are queued.

#3 Updated by hans almost 3 years ago

Here's a log with a little more info:

W/libsqlfs(16083): sqlfs_t_init 0x624572a0 sqlite3_open complete: 0x623c8078
W/libsqlfs(16083): sqlfs_t_init 0x624472f0 sqlite3_open complete: 0x62447a90
I/FileBrowser(16083): libsqlfs: detachThread(/secureselfie_1427230250020.jpg)
W/libsqlfs(16083): sqlfs_detach_thread 0x20 0x624472f0
W/libsqlfs(16083): sqlfs_t_finalize 0x624472f0
W/libsqlfs(16083): sqlfs_t_finalize 0x624472f0 sqlite3_close 0x62447a90
W/libsqlfs(16083): sqlfs_t_init 0x62448008 sqlite3_open complete: 0x61bc38b8
I/FileBrowser(16083): libsqlfs: detachThread(/secureselfie_1427230243408.jpg)
W/libsqlfs(16083): sqlfs_detach_thread 0x20 0x62448008
W/libsqlfs(16083): sqlfs_t_finalize 0x62448008
W/libsqlfs(16083): sqlfs_t_finalize 0x62448008 sqlite3_close 0x61bc38b8
W/libsqlfs(16083): sqlfs_t_init 0x62f11378 sqlite3_open complete: 0x61bc38b8
I/FileBrowser(16083): libsqlfs: detachThread(/secureselfie_1427230179025.jpg)
W/libsqlfs(16083): sqlfs_detach_thread 0x20 0x62f11378
W/libsqlfs(16083): sqlfs_t_finalize 0x62f11378
W/libsqlfs(16083): sqlfs_t_finalize 0x62f11378 sqlite3_close 0x61bc38b8
W/libsqlfs(16083): library routine called out of sequence

#4 Updated by n8fr8 almost 3 years ago

Even if I use multiple new Thread().start() etc with IOCipher it works just fine. I don't need to marshall everything into one thread.

#5 Updated by hans almost 3 years ago

It work fine to start with, but then each thread will never close its connection to SQLite, nor free the memory it is using for sqlfs. Also, the app won't be able to run unmount(), which is what wipes the password from memory.

#6 Updated by n8fr8 almost 3 years ago

unmount() works fine in this scenario. WHen using a traditional thread, that thread is destroyed/gc'd unlike in the AsyncTask setup.

#7 Updated by hans almost 3 years ago

Ah right, yeah, creating and destroying a thread should work fine. For some reason I thought you were using a thread pool.

Also available in: Atom PDF