# SQLite: a read-only probe can invalidate another writer's exclusion

Research supplement prepared on 2026-10-21. The public interpretation belongs to
[Hesela's descriptor-lifetime analysis](https://hesela.com/analyses/atomic-rename-directory-durability/#sqlite-lock-bypass).
This package retains the executable method, provenance and native observations.

## Main result

In the pinned Linux/unix-VFS fixtures, a raw read-only open, 16-byte read and close
of the active database in the writer's process admitted a second writer. Under
TRUNCATE and PERSIST rollback journaling, both COMMIT calls returned success,
yet one acknowledged row update disappeared when both rows shared a table page.
A subsequent integrity_check returned ok. The same interaction reproduced on the
distribution SQLite 3.45.1 build and a source-verified SQLite 3.54.1 build.

This is a controlled reproduction of documented misuse of POSIX locks, not a
new SQLite vulnerability, supported concurrent-write behavior, corruption rate,
or proof of a filesystem defect. No real database was opened by the runner.

## Files and replay

- [observe.py](observe.py): standard-library Python runner. Linux, Python 3.11+ and the unix VFS
  are required. It creates only private temporary fixtures, never takes a user
  database path, bounds subprocess time, closes all connections/descriptors and
  refuses an existing output. Peer processes exec a new Python interpreter.
- [system.json](system.json) and [3.54.1.json](3.54.1.json): immutable native observations, 112 cases per build.
- [verify.py](verify.py): checks all cases, controls, result classifications and source hash.
- [test_observe.py](test_observe.py): mutation tests, native controls, and output-preservation test.
- [synthesis.md](synthesis.md): publication-ready interpretation and corpus integration map.
- [sources.json](sources.json): primary-source locations, scope, access date and build provenance.
- [manifest.json](manifest.json): SHA-256 inventory of retained source, text and observations.

Run from this directory:

```sh
python3 observe.py --output replay.json
python3 verify.py replay.json
python3 bundle.py --check
python3 -m unittest -v test_observe.py
python3 -O -m unittest -v test_observe.py
```

The recorded case matrix is four journal modes (DELETE, TRUNCATE, PERSIST, WAL),
two layouts, seven interventions, two repetitions, on each of two builds.
The 224 rows are controlled configurations, not independent sampled incidents.
Repeated runs on one host do not estimate production frequency or confidence.

Also download [bundle.py](bundle.py), [summary.json](summary.json) and
[LICENSE](LICENSE). Keep these files together for the hash inventory and tests.
The check mode verifies hashes and recomputes the summary without writing;
running bundle.py without --check deliberately regenerates the summary and manifest.

## Method

Each fixture starts with A=0 and B=0. The owner begins IMMEDIATE and updates A=1,
without committing. Before any intervention, a new process attempts BEGIN
IMMEDIATE and must get SQLITE_BUSY. The chosen intervention occurs in the owner
unless explicitly labeled separate-process-read. A new peer then attempts BEGIN,
writes B=10 and commits. Its post-commit SELECT is retained. Only after that peer
exits does the owner attempt COMMIT. All handles are closed before a fresh
connection reads the final rows and runs the full integrity_check.

Both processes explicitly select the same journal mode, synchronous=FULL, and
the unix VFS. The owner disables cache spill and automatic WAL checkpoints.
The fixture is tiny: page size 4096, table root page 2 for the two-row layout;
separate table roots 2 and 3 for the two-table layout. Total page counts (2 or 3)
are checked. The experiment does not mutate database bytes directly, truncate
journals, inject SQLite return values or kill a transaction.

Interventions: none; raw main-file open/read/close; the same descriptor retained
until owner shutdown; an unrelated inode read/close; a same-library SQLite
connection read/close; raw read/close in a separate process; raw read/close through
a hard-link alias. The alias is only used by the raw reader, never as a SQLite
database connection name. A hard-link result is an inode-identity control, not
advice to access a database under multiple SQLite names.

The final logical oracle asks whether B=10 remains after B's acknowledged commit.
A never changes B. The integrity checker cannot answer that historical question.
The owner's connection-state flag is logged but is not treated as an OS-lock
measurement. Admission is measured through a real independent writer attempt.

## Builds

The system build reports SQLite 3.45.1 with a distribution-modified source ID
ending in alt1; do not label it a pristine upstream 3.45.1 reproduction. Its
compile options, loaded-library hash and kernel are in system.json. Both builds
used Python 3.12.3 and Linux 6.8.0-146-generic on x86_64.

For 3.54.1, the existing official amalgamation was read without modifying the
shared provider. Its SHA3-256 matches the release-page value in sources.json.
A private library compatible with the Python binding was built as follows:

```sh
gcc -O2 -fPIC -shared -DSQLITE_THREADSAFE=1 sqlite3.c \
  -o libsqlite3.so.0 -lpthread -ldl -lm
LD_LIBRARY_PATH="$PWD" python3 /path/to/observe.py --output replay-3.54.1.json
```

The source can be obtained from the official URL in sources.json; check its hash
before compiling. The runner records the actually loaded SQLite version,
source ID, compile options and library hash. No pip packages or new dependencies
are needed. Different build flags prevent attributing any possible difference
solely to a version number. Here both builds exhibited the same result pattern.

The filesystem string ext2/ext3 is stat -f's label, not a complete mount/storage
description. No network filesystem, Windows, alternate VFS, power interruption,
thread scheduler, page-spill workload, or generic WAL safety was tested.

## Rights

Hesela-authored Python code: MIT, see LICENSE.
Hesela-authored observations and summaries: CC0-1.0.
Hesela-authored prose: CC BY 4.0.
External documentation is linked, not redistributed. SQLite upstream source
remains under its own public-domain dedication; no upstream source/binary is
included in this research package.
