sqlite: two reentrancy guard gaps let a callback free the object SQLite is still usingΒ #65428
Copy link
Copy link
Closed
Labels
sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
Description
Activity
Confirming this reproduces on macOS arm64 against
main(v27.0.0-pre). One thing worth adding: it is more deterministic than the report suggests. I get exit 139 on 8 of 8 runs, and the default allocator crashes just as reliably as withMallocScribble=1 MallocPreScribble=1 MallocNanoZone=0, so the allocator flags were not needed here to see it.DatabaseSync::Exec()and the changeset-apply path already hold aBaseObjectPtr<DatabaseSync>across the SQLite call for this same hazard, but that only keeps GC from collecting the database. An explicitsession.close()inside the callback callssqlite3session_delete()while SQLite is still using the session, which that guard does not cover.- addedsqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
on Aug 21, 2026 - added a commit that references this issue
on Aug 28, 2026 - added a commit that references this issue
on Aug 30, 2026 - added a commit that references this issue
on Sep 3, 2026 - added a commit that references this issue
on Sep 15, 2026
Metadata
Metadata
Assignees
Labels
sqliteIssues and PRs related to the SQLite subsystem.Issues and PRs related to the SQLite subsystem.
Version
main(03fb384)Platform
Subsystem
sqlite
What steps will reproduce the bug?
Free memory that SQLite is still using from a callback:
How often does it reproduce? Is there a required condition?
The fault always occurs, but it's not always visible under the default allocator. Run with
MallocScribble=1 MallocPreScribble=1 MallocNanoZone=0on macOS and you get exit 139 deterministically; without it, the script can exit 0.What is the expected behavior? Why is that the expected behavior?
statement.close()should throwERR_INVALID_STATE. Perdoc/api/sqlite.md:What do you see instead?
A use-after-free. Under
MallocScribble, lldb stops insqlite3VdbeMemSetNull(pMem=0xaaaaaaaaaaaaaaaa)withEXC_BAD_ACCESS.Additional information
No response