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

sqlite3.c:60597: pagerOpenWalIfPresent: Assertion `pPager->eState==PAGER_OPEN' failed. #167

Closed
rogerbinns opened this issue Jun 8, 2024 · 6 comments

Comments

@rogerbinns
Copy link

Build apsw-sqlite3mc with --debug so assertions are enabled.

$ python3 -m apsw.mctests -v
APSW debug build: missing sys.apsw_fault_inject_control
testBackup (__main__.MultipleCiphers.testBackup)
Check backup restrictions ... ok
testBasic (__main__.MultipleCiphers.testBasic) ... ok
testCompileOptions (__main__.MultipleCiphers.testCompileOptions)
Check secure compilation flags were used ... ok
testKey (__main__.MultipleCiphers.testKey)
Ensure a key sticks ... ok
testMcIssue156 (__main__.MultipleCiphers.testMcIssue156)
Check memory mapping ... ok
testReadmeApplyEncryption (__main__.MultipleCiphers.testReadmeApplyEncryption)
readme apply_encryption ... python3: /space/mc/sqlite3/sqlite3.c:60597: pagerOpenWalIfPresent: Assertion `pPager->eState==PAGER_OPEN' failed.
Aborted (core dumped)
@rogerbinns
Copy link
Author

rogerbinns commented Jun 8, 2024

It was this commit re-enabling sqlicipher that made the assertion failure start happening.

@utelle
Copy link
Owner

utelle commented Jun 8, 2024

I will look into this.

@utelle
Copy link
Owner

utelle commented Jun 8, 2024

It was this commit re-enabling sqlicipher that made the assertion failure start happening.

I made a quick test. IMHO the problem has nothing to do with SQLCipher. The reason must be something else. The test crashes already on setting the invalid hexkey. Other tests like the backup test still succeed.

So, something seems to go wrong on applying a key for the second time. At the moment I don't know yet, why.

@rogerbinns
Copy link
Author

I used cvise to reduce it. The first user_version pragma is cricitcal, and the second is when the assertion fails.

import apsw
db = apsw.Connection("mcdb")
db.pragma("user_version", "")
db.pragma("hexkey", "1122")
db.pragma("user_version", "")

@utelle
Copy link
Owner

utelle commented Jun 9, 2024

I used cvise to reduce it. The first user_version pragma is cricitcal, and the second is when the assertion fails.

import apsw
db = apsw.Connection("mcdb")
db.pragma("user_version", "")
db.pragma("hexkey", "1122")
db.pragma("user_version", "")

Thanks. That shows that the SQLCipher configuration is most likely not involved.

AFAICT SQLite deals with the assertion situation correctly later on. For example, the release version of the SQLite shell works as expected and doesn't show any misbehaviour. Of course, this is no excuse for an obvious bug, and it will be fixed. It just will take some time.

@utelle
Copy link
Owner

utelle commented Jun 9, 2024

After some hours of debugging I think I found the reason for the assertion. Internally the wrong key was correctly detected, but it was not properly communicated to upper level functions. Actually, the error is detected later in SQLite, but in debug mode the assertion is raised first.

Commit utelle/apsw-sqlite3mc@ca146dd includes an updated amalgamation. Hopefully all tests will now run as expected.

utelle added a commit that referenced this issue Jun 9, 2024
If decrypting a page failed due to a wrong passphrase, the error was detected at VFS level, but not communicated properly to higher level SQLite functions. In debug mode that could lead to raising an assertion, although the error was detected and handled by SQLite later on.
@utelle utelle closed this as completed Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants