Skip to content

Commit c087b71

Browse files
Spxgshoestringr
andauthored
IDBMirrorVFS: Fix database corruption caused by unfilled blocks (rhashimoto#259)
* IDBMirrorVFS: Fix database corruption caused by unfilled blocks * Wrap long lines; no functional change. --------- Co-authored-by: Roy Hashimoto <roy@shoestringresearch.com>
1 parent 52f5c4c commit c087b71

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/examples/IDBMirrorVFS.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ export class IDBMirrorVFS extends FacadeVFS {
333333

334334
if (file.flags & VFS.SQLITE_OPEN_MAIN_DB) {
335335
this.#requireTxActive(file);
336+
// SQLite is not necessarily written sequentially, so fill in the
337+
// unwritten blocks here.
338+
for (let fillOffset = file.txActive.fileSize;
339+
fillOffset < iOffset; fillOffset += pData.byteLength) {
340+
file.txActive.blocks.set(fillOffset, new Uint8Array(pData.byteLength));
341+
}
336342
file.txActive.blocks.set(iOffset, pData.slice());
337343
file.txActive.fileSize = Math.max(file.txActive.fileSize, iOffset + pData.byteLength);
338344
file.blockSize = pData.byteLength;

0 commit comments

Comments
 (0)