sqlcipher/android-database-sqlcipher — pull request #140 by ph4r05 (2014-09-15 14:28:33+00:00)
Title: Fixed ICU extraction for multiple processes.

Fixes segfault in the following scenario: two Android processes launched
during application start tried to extract ICU file at the same time
overwriting destination file by each other. This results in segmentation
fault while loading ICU in native library.

The segmentation fault ocurred in checkDataItem function at external/icu4c/common/udata.cpp. In particular on line with "pHeader->dataHeader.magic1==0xda".

How to reproduce a problem:
* Create 2 independent processes in android application, e.g., two services running in different process.
* Start both services on application start.
* Open a (different) SQLite databases in both processes.

This proposed patch fixes the problem by:
1) using file locking so only one process extracts ZIP archive and writes the destination in time;
2) by extracting to a temporary file, then renaming it to the destination file name;
3) by forcing flushing/syncing file to file system using channels and sync so native library can process it.