vfs: report files opened through vfs.New as read-only to SQLite

Problem. vfsOpen set its out-flags to int32(os.O_RDONLY), which is 0, while SQLite reads them for SQLITE_OPEN_READONLY. A database opened through a VFS made by vfs.New was therefore writable as far as SQLite knew, though vfsio has no xWrite, xTruncate or xSync. An UPDATE failed with a misleading SQLITE_NOMEM from the journal open; after PRAGMA journal_mode=OFF the same UPDATE reached the missing xWrite and the process panicked with a nil pointer dereference, from SQL text alone.

Change. The out-flags now carry SQLITE_OPEN_READONLY, so every write fails with SQLITE_READONLY. CHANGELOG entry under v1.61.1.

Testing. TestVFSWriteRefused runs UPDATE and DELETE with the journal on and off and checks the table afterwards. With the old out-flags it fails at the first UPDATE with SQLITE_NOMEM. The vfs tests pass on darwin/arm64, also under -race.

This is the fix from my mail of 29 September.

Merge request reports

Loading
Loading