This commit is contained in:
Nuno Cruces
2025-03-24 19:59:19 +00:00
parent c067e3630b
commit 6c296231a5
3 changed files with 4 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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))
}