Visitar URL original
Fix crash in SQL query results when stale editor positions are used by rachavz · Pull Request #4115 · sqlitebrowser/sqlitebrowser · GitHub
Skip to content

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

Merged
mgrojo merged 3 commits into
sqlitebrowser:masterfrom
rachavz:fix/crash-stale-editor-positions
Oct 4, 2026
Merged

mgrojo merged 3 commits into
sqlitebrowser:masterfrom
rachavz:fix/crash-stale-editor-positions

Conversation

@rachavz

@rachavz rachavz commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

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

mgrojo and others added 2 commits March 31, 2026 14:09
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.
@mgrojo

mgrojo commented Jun 21, 2026

Copy link
Copy Markdown
Member

@rachavz sorry about the delay. Could you resolve the conflict?

@mgrojo
mgrojo merged commit 9dda068 into sqlitebrowser:master Oct 4, 2026
23 checks passed
@rachavz
rachavz deleted the fix/crash-stale-editor-positions branch October 4, 2026 22:30
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

3 participants