From 6c296231a52d88a13c33658c107d08777a1ba9e0 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 24 Mar 2025 19:59:19 +0000 Subject: [PATCH] Fix #249. --- config.go | 2 ++ util/sql3util/sql3util.go | 2 +- vfs/cksm.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index d9ce9f5..d52cc05 100644 --- a/config.go +++ b/config.go @@ -350,6 +350,8 @@ func (c *Conn) HardHeapLimit(n int64) int64 { } // EnableChecksums enables checksums on a database. +// If the database is in WAL mode, +// you should shutdown and reopen all database connections before continuing. // // https://sqlite.org/cksumvfs.html func (c *Conn) EnableChecksums(schema string) error { diff --git a/util/sql3util/sql3util.go b/util/sql3util/sql3util.go index 6be6192..f2e33c0 100644 --- a/util/sql3util/sql3util.go +++ b/util/sql3util/sql3util.go @@ -5,5 +5,5 @@ package sql3util // // https://sqlite.org/fileformat.html#pages func ValidPageSize(s int) bool { - return 512 <= s && s <= 65536 && s&(s-1) == 0 + return s&(s-1) == 0 && 512 <= s && s <= 65536 } diff --git a/vfs/cksm.go b/vfs/cksm.go index 041defe..1610549 100644 --- a/vfs/cksm.go +++ b/vfs/cksm.go @@ -68,7 +68,7 @@ func (c cksmFile) ReadAt(p []byte, off int64) (n int, err error) { func (c cksmFile) WriteAt(p []byte, off int64) (n int, err error) { // SQLite is writing the first page of a database file. - if c.isDB && off == 0 && len(p) >= 100 && + if (!c.isDB || off == 0) && sql3util.ValidPageSize(len(p)) && bytes.HasPrefix(p, []byte("SQLite format 3\000")) { c.init((*[100]byte)(p)) }