{"record":{"id":"c6295e2a4f7731f3","repo":"rqlite/rqlite","slug":"invalid-sqlite-data-c6295e","errorCode":null,"errorMessage":"invalid SQLite data","messagePattern":"invalid SQLite data","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/store.go","lineNumber":2012,"sourceCode":"\tdefer os.Remove(f.Name())\n\tdefer f.Close()\n\n\tcw := progress.NewCountingWriter(f)\n\tcm := progress.StartCountingMonitor(func(n int64) {\n\t\ts.logger.Printf(\"boot process installed %d bytes (%s)\", n, humanize.Bytes(uint64(n)))\n\t}, cw)\n\tn, err := func() (int64, error) {\n\t\tdefer cm.StopAndWait()\n\t\tdefer f.Close()\n\t\treturn io.Copy(cw, r)\n\t}()\n\tif err != nil {\n\t\treturn n, err\n\t}\n\n\t// Confirm the data is a valid SQLite database.\n\tif !sql.IsValidSQLiteFile(f.Name()) {\n\t\treturn n, fmt.Errorf(\"invalid SQLite data\")\n\t}\n\n\t// Raft won't snapshot unless there is at least one unsnapshotted log entry,\n\t// so prep that now before we do anything destructive.\n\tif af, err := s.Noop(\"boot\"); err != nil {\n\t\treturn n, err\n\t} else if err := af.Error(); err != nil {\n\t\treturn n, err\n\t}\n\n\t// Swap in new database file.\n\tif err := s.db.Swap(f.Name(), s.dbConf.FKConstraints, true); err != nil {\n\t\treturn n, fmt.Errorf(\"error swapping database file: %v\", err)\n\t}\n\n\t// Swapping in a new database unregisters any registered CDC hooks, so signal that it\n\t// needs to be reregistered on the next change.\n\ts.cdcRegistered.Unset()","sourceCodeStart":1994,"sourceCodeEnd":2030,"githubUrl":"https://github.com/rqlite/rqlite/blob/7586a4d1bdbd9a5a80021664c5a863cd850adb60/store/store.go#L1994-L2030","documentation":"Store restores a node (e.g., via /boot) by receiving SQLite data, writing it to a temp file, and validating it with sql.IsValidSQLiteFile before installing it. If the uploaded bytes are not a valid SQLite database (bad header/format, truncated transfer, compressed data sent uncompressed), the restore is aborted with 'invalid SQLite data' and the node's existing database is left untouched.","triggerScenarios":"POSTing to /boot with a body that is not a genuine SQLite file: an SQL text dump instead of a .db file, a gzip-compressed file uploaded without ?compress flag (or vice versa), truncated/corrupt download, or the wrong file entirely.","commonSituations":"Operators backing up with ?fmt=sql and then trying to boot from the SQL dump; curl scripts misplacing the ?compress parameter; interrupted downloads reused as restore sources; backups from non-SQLite sources.","solutions":["Upload an actual SQLite database file (from /db/backup without fmt=sql), not a SQL text dump.","Match compression flags: add ?compress to the boot request if the payload is gzipped, or send uncompressed data without it.","Validate the file locally before upload: `file backup.db` should say 'SQLite 3 database'.","Re-download the backup if truncated; compare checksums with the source."],"exampleFix":"# before\ncurl -X POST http://node:4001/boot --data-binary @backup.sql.gz\n# after\ncurl -X POST 'http://node:4001/boot?compress' --data-binary @backup.db.gz","handlingStrategy":"validation","validationCode":"hdr := make([]byte, 16)\nf, _ := os.Open(restoreFile)\nf.Read(hdr)\nif string(hdr[:15]) != \"SQLite format 3\" {\n    return errors.New(\"not a SQLite database; use /db/backup without fmt=sql\")\n}","typeGuard":"func isValidSQLiteFileHeader(b []byte) bool {\n    return len(b) >= 16 && string(b[:15]) == \"SQLite format 3\"\n}","tryCatchPattern":"resp, err := http.Post(bootURL, \"application/octet-stream\", body)\nif resp.StatusCode != 200 && strings.Contains(readBody(resp), \"invalid SQLite data\") {\n    // wrong format: re-export with /db/backup, recheck compress flag\n}","preventionTips":["Restore only from /db/backup output (binary), never from fmt=sql dumps","Keep ?compress consistent between backup and boot","Checksum backups after download and before restore","Test restores with `file` / sqlite3 CLI before pointing at production"],"tags":["restore","validation","sqlite","backup"],"backgroundTag":"invalid-sqlite-file","analyzedSha":"7586a4d1bdbd9a5a80021664c5a863cd850adb60","analyzedAt":"2026-09-03T07:03:02.260Z","contentChangedAt":"2026-09-03T07:03:02.260Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}