Skip to content

Fix crash in SQL query results when stale editor positions are used#4115

Open
rachavz wants to merge 13 commits intosqlitebrowser:masterfrom
rachavz:fix/crash-stale-editor-positions
Open

Fix crash in SQL query results when stale editor positions are used#4115
rachavz wants to merge 13 commits intosqlitebrowser:masterfrom
rachavz:fix/crash-stale-editor-positions

Conversation

@rachavz
Copy link
Copy Markdown

@rachavz rachavz commented Apr 1, 2026

Fixes #4109

Summary

Random crash when a cell with ordinary text is selected in the SQL query results table.

Root cause: The query_logger lambda in MainWindow.cpp captures the SQL editor state and is invoked via Qt::QueuedConnection. By the time it executes asynchronously, the editor content may have changed, making from_position/to_position stale. This triggers a Scintilla assertion failure in SCI_GETTEXTRANGE when positions are out of bounds.

Fix:

  • Added a clampToEditor helper that clamps line and index values to valid editor bounds
  • Applied clamping to all position calculations used in the query_logger lambda
  • Ensured sqlWidget->finishExecution() is called before any early return to avoid hanging the UI

Testing

  • Built successfully on Windows 11 with MSVC 2026, Qt 5.15.2
  • Manually tested SQL query execution - no crashes when selecting cells in results

mdmahendri and others added 13 commits January 4, 2026 07:27
By default word wrap for QTableView is enabled. If cell's text include
quated string or colon or dash (like date: 2025-09-01 00:00:01)
then text truncated too much.
For example instead of "2005-09-01 00:00:..." truncate to
"2005-09-01..."
- switch option to positive logic
- invoke unconditional setWordWrap()
Given that sqlite3 does not allow case-differing identifiers, and in some
situations the stored name in `schemata` may differ only in case from the name used in
the stored SQL create statement, the search of DB objects must be done
case-insensitively.

See issue sqlitebrowser#4110.
This adds a new setting in "Preferences > Database" (defaulting to false)
to watch the database file when opened in read-only mode and refresh the
browser on updated file.

See issues sqlitebrowser#1767 and sqlitebrowser#2508.
Added option to replace non-alphanumeric characters in column name with
underscore. SQL editor does not complete correctly column names
containing space, column and etc.
Replace non-alphanumeric with underscore
The query_logger lambda is called via Qt::QueuedConnection, so editor
content may have changed by the time it executes. This caused Scintilla
assertion failures when from_position/to_position exceeded document
length, or when line numbers were out of bounds after conversion.

- Clamp from_position/to_position with qBound before use
- Clamp line indices against actual line lengths before setErrorIndicator
- Call finishExecution on early return when editor is empty
- Guard line iteration loops with lines boundary check

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Random crash when cell with ordinary text selected in SQL query results table

4 participants