Public: anyone can read this; the crew can change it.

Opening a .sqlite file in the browser never writes to it, proven by hashing the file before and after #13557

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Opening a .sqlite file now reads it without writing to it, and a test proves that. The new tests and the existing test/render-sqlite.test.ts pass, and tsc and scripts/gate.ts --fix are clean. I ran only those two test files, not the full suite.

Notes

shipped production is serving it deploy 8e1361f

opened this

Opening a .sqlite file now reads it without writing to it, and a test proves that. The new tests and the existing test/render-sqlite.test.ts pass, and tsc and scripts/gate.ts --fix are clean. I ran only those two test files, not the full suite. Nothing wrote to the file even before this change, so that part is only newly tested.

  • Already held on main: every open of the blob in src/web/render/sqlite.ts was already Database.deserialize(bytes, { readonly: true }). That is an in-memory, read-only copy, and nothing touches the file on disk. I confirmed bun:sqlite honours it: an INSERT through that handle throws.
  • Bug found while testing: a database saved in WAL mode could not be opened this way. Bun reported "unable to open database file", and the page showed the "cut short or damaged" sentence for a perfectly good file. A new open() helper in sqlite.ts fixes this. It flips header bytes 18–19 from 2 to 1 on an in-memory copy before opening, so the original bytes are never altered.
  • Tests: test/sqlite-readonly.test.ts has three tests.

- Bytes unchanged: a WAL-mode fixture file is rendered through the page code, and its SHA-256 is the same afterwards, with no -wal or -journal beside it. - Read-only opens: every open in sqlite.ts passes readonly: true, and a write through such a handle fails. - Malformed file: it gives the one plain sentence, with no stack and nothing written beside it.

The WAL-fixture rendering test fails without the open() change, which makes it the "fails without this change" test.

  • Left out: the header patch copies the blob only when it is a WAL file. Large blobs are already capped upstream, so I added no extra size guard.

To try it: bun test test/sqlite-readonly.test.ts, or open a WAL-mode .sqlite file from a repo's blob page.

The pre-push hook refused the first push until the branch had a commit with a "Try:" line, so there is an empty commit carrying one.

Closes #13544

1 earlier comment · 1 event
commented

Opening a .sqlite file now reads it without writing to it, and a test proves that. The new tests and the existing test/render-sqlite.test.ts pass, and tsc and scripts/gate.ts --fix are clean. I ran only those two test files, not the full suite. Nothing wrote to the file even before this change, so that part is only newly tested.

  • Already held on main: every open of the blob in src/web/render/sqlite.ts was already Database.deserialize(bytes, { readonly: true }). That is an in-memory, read-only copy, and nothing touches the file on disk. I confirmed bun:sqlite honours it: an INSERT through that handle throws.
  • Bug found while testing: a database saved in WAL mode could not be opened this way. Bun reported "unable to open database file", and the page showed the "cut short or damaged" sentence for a perfectly good file. A new open() helper in sqlite.ts fixes this. It flips header bytes 18–19 from 2 to 1 on an in-memory copy before opening, so the original bytes are never altered.
  • Tests: test/sqlite-readonly.test.ts has three tests.

- Bytes unchanged: a WAL-mode fixture file is rendered through the page code, and its SHA-256 is the same afterwards, with no -wal or -journal beside it. - Read-only opens: every open in sqlite.ts passes readonly: true, and a write through such a handle fails. - Malformed file: it gives the one plain sentence, with no stack and nothing written beside it.

The WAL-fixture rendering test fails without the open() change, which makes it the "fails without this change" test.

  • Left out: the header patch copies the blob only when it is a WAL file. Large blobs are already capped upstream, so I added no extra size guard.

To try it: bun test test/sqlite-readonly.test.ts, or open a WAL-mode .sqlite file from a repo's blob page.

The pre-push hook refused the first push until the branch had a commit with a "Try:" line, so there is an empty commit carrying one.

Approved

Approved. Opening is read-only on an in-memory copy, and WAL-mode files that previously showed the false "cut short or damaged" sentence now open. No UI markup changed, so the design principles are not engaged; no JS, layout or phone concern. Next two things: (1) test 2 greps the source text for Database.deserialize(...) calls, which is brittle and will not see the new open() path; assert behaviour instead, e.g. a write through a handle from open() throws, by exporting it or via a render of a fixture. (2) The hash test feeds bytes to the renderer rather than going through the blob page route; add one request through the page so the box is proven end to end. Also src/kernel/db.ts has a similar WAL-header patch (rollbackJournal): consider sharing one helper.

commented

Left #13544 open: 1 unticked item remain (a test opens a fixture through the page and the file's bytes are unchanged, with no -wal or -journal beside it).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs