Skip to content

Commit 2f74ba3

Browse files
Fix rhashimoto#260. Avoid IDBBatchAtomicVFS null dereference. (rhashimoto#263)
Co-authored-by: Roy Hashimoto <[email protected]>
1 parent c087b71 commit 2f74ba3

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/examples/IDBBatchAtomicVFS.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -487,25 +487,27 @@ export class IDBBatchAtomicVFS extends WebLocksMixin(FacadeVFS) {
487487
break;
488488
case VFS.SQLITE_FCNTL_SYNC:
489489
this.log?.('xFileControl', file.path, 'SYNC');
490-
const commitMetadata = Object.assign({}, file.metadata);
491-
const prevFileSize = file.rollback.fileSize
492-
this.#idb.q(({ metadata, blocks }) => {
493-
metadata.put(commitMetadata);
494-
495-
// Remove old page versions.
496-
for (const offset of file.changedPages) {
497-
if (offset < prevFileSize) {
498-
const range = IDBKeyRange.bound(
499-
[file.path, -offset, commitMetadata.version],
500-
[file.path, -offset, Infinity],
501-
true);
502-
blocks.delete(range);
490+
if (file.rollback) {
491+
const commitMetadata = Object.assign({}, file.metadata);
492+
const prevFileSize = file.rollback.fileSize
493+
this.#idb.q(({ metadata, blocks }) => {
494+
metadata.put(commitMetadata);
495+
496+
// Remove old page versions.
497+
for (const offset of file.changedPages) {
498+
if (offset < prevFileSize) {
499+
const range = IDBKeyRange.bound(
500+
[file.path, -offset, commitMetadata.version],
501+
[file.path, -offset, Infinity],
502+
true);
503+
blocks.delete(range);
504+
}
503505
}
504-
}
505-
file.changedPages.clear();
506-
}, 'rw', file.txOptions);
507-
file.needsMetadataSync = false;
508-
file.rollback = null;
506+
file.changedPages.clear();
507+
}, 'rw', file.txOptions);
508+
file.needsMetadataSync = false;
509+
file.rollback = null;
510+
}
509511
break;
510512
case VFS.SQLITE_FCNTL_BEGIN_ATOMIC_WRITE:
511513
// Every write transaction is atomic, so this is a no-op.

0 commit comments

Comments
 (0)