-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Mutex error in mcFindDbMainFileName #157
Comments
I suspect uninitialized memory in the The default VFS (which will be something like
The latter is more likely than the former. |
The code doesn't change the VFS order, although there are other tests that do. The C code of what is going on is:
But crucially |
Commit ec04fad fixes the problem. Although the internal method to find the Multiple Ciphers VFS in the VFS stack worked correctly, the wrong VFS pointer was passed onwards. Now the correct pointer is used and all seems to work as expected. However, AFAICT handling of the control code |
When your create a VFS you can specify the structure fields including name, make default, max pathname, iVersion, and which pointers you want left as For each callback it will the corresponding method name that the developer has to implement. Exceptions/results from that method are then returned back to SQLite. If you specified a base, then that VFS's method can be called explicitly via It is really analogous to implementing the structure methods yourself in Python instead of C, and no more than that.
I'll try the main APSW test suite again using the |
Yes, that is clear. However, a VFS should typically return its own name to the caller, if it is a stand-alone VFS. If it is VFS shim it should implement this method like the demo VFS shims coming with SQLite. The VFS name is the combination of the name coming from the underlying VFS prepended by the name of the VFS shim. Unfortunately, this is not really documented, except the implementation code in the sample VFSes.
The sample given in the first issue post inherits the default VFS (which could be for example While a list of all registered VFSes can be produced, because the VFSes are chained in a linked list, there is no comparable mechanism available for accessing the VFS stack (where you have 1 or more VFS shims). In our use case it is not necessary to know that the VFS
For the
AFAICT the VFS stuff should simply work - as long as the VFS doesn't plays tricks on the number of reserved bytes per page. |
This is semantically difficult in APSW. There is a distinction between a VFS and a VFSFile. There is absolutely no requirement in the code that a VFSFile correspond to a VFS. It is possible to have VFSFile that doesn't have a corresponding VFS. Both can shim to different VFS too. I've made an issue to work on it.
BTW APSW has a shell too. Just do I also implemented that command, but it just prints the Do try the I still think that relying on names to a barely documented fcntl is fragile. The good news is that code that "inherits" including example code all default to passing file controls to their base. |
AFAIK a VFSFile is created through a call to the When method If the SQLite3MC VFS is involved, then the returned name string will contain the string Unfortunately, this is the only way to determine the pointer to a VFS shim within a VFS stack. There is no SQLite API to walk through the VFS stack.
In the SQLite shell you have 3 VFS related dot commands:
Your APSW implementation should do the same, if possible.
This command displays a list of all registered VFSes. Unfortunately, there can be more than one registered VFS using the SQLite3MC VFS shim. This command doesn't help to identify which one is used for the current VFSFile.
My code uses the SQLite API function Your implementation should prepend its own VFS name (here |
BTW, on initialization SQLite3MC registers a VFS using the SQLite3MC VFS shim and the normal default VFS, and makes it the new default VFS. Sometimes this is not what a user wants. Sometimes a user wants to use a non-default VFS together with encryption. There are 2 possible ways to achieve this:
|
At the C level a VFS consists of a bundle of two data structures - sqlite3_vfs and sqlite3_io_methods. The former implements Conventional VFS implement both in the same source file. APSW makes absolutely no requirement that there is any relation between them. The problem is that This is why I think you should not depend on I will implemented SQLITE_FCNTL_VFSNAME in APSW but only for the diagnostic purposes. That will also include updating the APSW shell The It is entirely reasonable that a VFS wanting to use encrypted storage has to pass on all calls to |
Yes. And that imposes a problem for SQLite3MC, when a codec needs to be located, but only the connection is known. A connection has an associated VFS, but the SQLite3MC VFS is not necessarily the top-level one. To find out whether the SQLite3MC VFS is member of the VFS stack or not,
I consulted once again the source code of the sample VFSes coming with SQLite. Actually, most of them do not use the real VFS name for generating the VFS name. Usually they use only something similar. That is, typically it is not possible to identify the associated VFS from this string. However, the SQLite3MC implementation returns the real VFS name.
I don't want to invent my own op code for this purpose, because there is always a chance it could collide with another op code. The op code name In the end it doesn't matter what other implementations of I know this is somewhat fragile, because a malicious implementation could fake the result string. Therefore the result is carefully checked. (If I can come up with a better solution in the future, I will change my implementation.)
SQLite's documentation says that
You are right, of course. One thing one has to keep in mind is that the SQLite3MC VFS shim will be incompatible with other VFSes or VFS shims which want to make use of reserved bytes on database pages themselves. |
There are 4 billion possible opcodes. If you are worried about a collision, I'll want winning lottery numbers from you! Use the number below. Make it so that the associated On the other hand depending on behaviour in a poorly documented arbitrarily manipulated string where others could use
As to how I came up with that number:
Since you are still nervous about a clash, I offer you a lookup in the magic number database showing it hasn't been used for anything. |
Citing from the SQLite VFS documentation:
So, you are right. that it is a common way to define one's own op codes. Nevertheless I think that the op code |
It looks like the the pragma wants to know which sqlite3_vfs has the |
With apsw-sqlite3mc create the following file and run it with a sanitizer python:
The code creates a new VFS named "test" then opens a not existing database
testdb
. Thetest
VFS in itsxOpen
implementation creates a new VFSFile which simply opens the database using the default VFS.When the pragma runs to set the encryption key the following sanitizer output is generated:
The same issue occurs with the same call stack in other places in apsw-sqlite3mc tests when setting encryption keys on every opened database via a connection hook.
The text was updated successfully, but these errors were encountered: