Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLCompileStatement crash DEMO #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package net.zetetic.tests;

import android.util.Log;

import androidx.annotation.NonNull;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteStatement;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class SQLCompileStatementFinalizeTest extends SQLCipherTest {

private final int count = 2;
private final boolean isLocking;

public SQLCompileStatementFinalizeTest(Boolean useLocking) {
isLocking = useLocking;
}

@Override
public boolean execute(final SQLiteDatabase database) {
database.setLockingEnabled(isLocking);
final CountDownLatch latchMain = new CountDownLatch(1);
final CountDownLatch latchTransaction = new CountDownLatch(1);
final CountDownLatch latchSQLRelease = new CountDownLatch(1);

database.execSQL("CREATE TABLE TestTable(text_value TEXT);");

Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {

for (int i = 0; i < count; i++) {
SQLiteStatement statement = database.compileStatement("DELETE FROM TestTable");
statement.executeUpdateDelete();
}

latchSQLRelease.countDown();

try {
latchTransaction.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});

Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
try {
latchSQLRelease.await();

database.beginTransaction();

latchTransaction.countDown();

long start = System.currentTimeMillis();
while (System.currentTimeMillis() < start + TimeUnit.SECONDS.toMillis(40)) {
new Object();
System.gc();
}
database.setTransactionSuccessful();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
database.endTransaction();
}

latchMain.countDown();
}
});

thread1.start();
thread2.start();

try {
latchMain.await();
} catch (InterruptedException e) {
e.printStackTrace();
return false;
}

return true;
}

@Override
public String getName() {
return "SQLCompileStatement crash, locking=" + isLocking;
}

}
3 changes: 2 additions & 1 deletion app/src/main/java/net/zetetic/tests/TestSuiteRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import net.sqlcipher.CursorWindow;
import net.sqlcipher.CursorWindowAllocation;
import net.sqlcipher.database.SQLiteDatabase;
import net.zetetic.ZeteticApplication;

import java.util.ArrayList;
Expand Down Expand Up @@ -70,6 +69,8 @@ private void runSuite() {
private List<SQLCipherTest> getTestsToRun() {
List<SQLCipherTest> tests = new ArrayList<>();

tests.add(new SQLCompileStatementFinalizeTest(false));
tests.add(new SQLCompileStatementFinalizeTest(true));
tests.add(new SummingStepTest());

tests.add(new JsonCastTest());
Expand Down