-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
CorruptError if SQLITE_CONFIG_MMAP_SIZE used #156
Comments
I have to admit that I have never experimented with the
Leaving out calling What happens, if you use At the moment I have no idea, what may cause the error. I'll have to try to reproduce the error in my development environment to find out what is going wrong. |
In the meantime I made a few experiments using the SQLite shell coming with the SQLite3 Multiple Ciphers releases. The parameter First, I used an older version of the shell I had at hand from other tests. If I used a value of 8192 I got the error "database disk image is malformed". With smaller values the error went away, although I did not reopen the database, but just reissued the Then I used the shell from the latest release. But I was unable to reproduce the error. I could set This makes it extremely difficult to track down the cause of the error. |
It doesn't matter whether key or hexkey is used. If I catch the CorruptError, turn mmap back off, and do a read again then all is fine. I also double checked the database is encrypted, and that calling the vfs xRead method does give the right results. The issue in your code is almost certainly how VFS xFetch is handled. I put a break point where I can get the sqlite3_io_methods and it does look correct:
|
The changes APSW makes to SQLite defaults are in src/apsw.c and only if statically compiling in the amalgamation which I am doing in this case.
Builds for PyPI also add SQLITE_ENABLE_COLUMN_METADATA configured in tools/setup-pypi.cfg |
Any other answer would have surprised me.
Maybe the SQLite compile time options used to compile APSW differ from those I typically use for the SQLite shell.
|
That can't be right for mcIoFetch. A simple fix is to make your interposer sqlite3_io_methods cap |
I will further analyze what SQLite does when using xFetch/xUnFetch. It is a bit irritating that writing encrypted content seems to work properly, in contrast to reading.
As a quick fix that would probably work. |
I did try setting the xFetch entry in Setting |
Setting method pointer to 0 is not a good idea. SQLite doesn't check for null pointer at some critical places (as I found out when I tried to add SQLite3 Multiple Ciphers to the WASM module).
Setting That is, your analysis is absolutely right that those 2 methods do not what they should, if encryption is enabled. |
Ok, in the meantime I inspected the SQLite code. IMHO the methods The real question is, why method @rogerbinns: Could you please find out which page getter method is set and whether it is correctly detected that the database is encrypted? The call stack when |
There are wiki instructions which is all I am doing to run the code at the top. This is with the updated sqlite3.c in that repo putting a breakpoint ion mcIoFetch
Hopefully this is enough. |
pPager in frame 2
|
I will set up the environment in my Linux environment and will try to further investigate the issue.
As can be seen the page getter method |
Ok, I tested under Linux based on the wiki instructions. Here are the test results:
No |
You only need the 6 lines of code in this issue report at the top to reproduce. The wiki has instructions at the bottom on how to set a breakpoint in code of your choice. In commit utelle/apsw-sqlite3mc@2c623e8 I temporarily worked around the issue which is why it doesn't show up now. That was to allow a build for test pypi to complete. I've now removed the workaround and added another test that explicitly checks memory mapping. |
This remove the temporary workaround from 2c623e8 and ensures a test using memory mapping is always run. Refs utelle/SQLite3MultipleCiphers#156
Thanks. In the meantime I have set up the project in my Linux environment, so that I can continue to test there.
I see now the |
Actually, it was only a small glitch. The codec pointer was set in the SQLite file structure a bit too late, so that the SQLite pager got the impression that no codec is in place and selected the page getter method for memory-mapped database files. Commit c95bd21 should fix the issue. I committed an updated amalgamation to apsw-sqlite3mc. |
I could run all tests without problems. Therefore closing this issue. Reopen if necessary. |
The following program causes CorruptError:
CorruptError is returned executing the select. Leaving out the hexkey also does not result in error.
If the mmap value is 8447 or less then the error does not occur. I was setting it to 2 **63 -1.
The text was updated successfully, but these errors were encountered: