Skip to content

Commit 6c29623

Browse files
committed
Fix #249.
1 parent c067e36 commit 6c29623

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ func (c *Conn) HardHeapLimit(n int64) int64 {
350350
}
351351

352352
// EnableChecksums enables checksums on a database.
353+
// If the database is in WAL mode,
354+
// you should shutdown and reopen all database connections before continuing.
353355
//
354356
// https://sqlite.org/cksumvfs.html
355357
func (c *Conn) EnableChecksums(schema string) error {

util/sql3util/sql3util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ package sql3util
55
//
66
// https://sqlite.org/fileformat.html#pages
77
func ValidPageSize(s int) bool {
8-
return 512 <= s && s <= 65536 && s&(s-1) == 0
8+
return s&(s-1) == 0 && 512 <= s && s <= 65536
99
}

vfs/cksm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (c cksmFile) ReadAt(p []byte, off int64) (n int, err error) {
6868

6969
func (c cksmFile) WriteAt(p []byte, off int64) (n int, err error) {
7070
// SQLite is writing the first page of a database file.
71-
if c.isDB && off == 0 && len(p) >= 100 &&
71+
if (!c.isDB || off == 0) && sql3util.ValidPageSize(len(p)) &&
7272
bytes.HasPrefix(p, []byte("SQLite format 3\000")) {
7373
c.init((*[100]byte)(p))
7474
}

0 commit comments

Comments
 (0)