Skip to content

The wasm driver's sqlite3_get_autocommit binding is asserted by cast, not checked #1074

Description

@sirtimid

Found reviewing #1021 (sirtimid/crank-rollback-integrity).

What

wasm.ts reaches the autocommit binding through an unchecked cast:

sqlite3.capi as Sqlite3Static['capi'] & AutocommitCapi

@sqlite.org/sqlite-wasm's index.d.ts declares CAPI as a generated member list with no index signature and no sqlite3_get_autocommit. The binding does exist in the installed build — but nothing verifies that.

If it is ever absent or renamed, getAutocommit is undefined and every read of inTransaction throws TypeError — from inside beginIfNeeded, commitIfNeeded and rollbackIfNeeded, i.e. the exact machinery #1021 exists to harden. Browser-only, at runtime, with no startup signal.

This is the one place in that diff where an as cast stands in for an unverified assumption about a foreign module, and it is load-bearing: replacing the cached _inTx with a live sqlite3_get_autocommit read is the headline fix of the kernel-store half.

Suggested fix

One line at init turns a scattered runtime TypeError into a clear startup failure:

typeof getAutocommit === 'function' ||
  Fail`sqlite3 capi lacks sqlite3_get_autocommit`;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions