Fix an assert that can fail if the database file is corrupted.
Version 3.8.6
Merge the 3.8.6 changes into the apple-osx branch.