Skip to content

Add null checks to prevent SIGSEGV when table lookup fails#4116

Open
rachavz wants to merge 14 commits intosqlitebrowser:masterfrom
rachavz:fix/null-checks-table-lookup
Open

Add null checks to prevent SIGSEGV when table lookup fails#4116
rachavz wants to merge 14 commits intosqlitebrowser:masterfrom
rachavz:fix/null-checks-table-lookup

Conversation

@rachavz
Copy link
Copy Markdown

@rachavz rachavz commented Apr 1, 2026

Summary

  • Adds null pointer checks at all call sites where getTableByName() result was dereferenced without protection, preventing SIGSEGV crashes
  • Fixes crash in browse data path, record retrieval, max value queries, and table alteration
  • Complements the case-insensitive lookup fix from commit 222e430

Details

Issue #4110 reports a SIGSEGV when browsing a table whose name in sqlite_master differs in case from the name in its CREATE TABLE statement (e.g. databases created by Turso). While commit 222e430 addressed the root cause with case-insensitive lookups, there were still 8 unprotected call sites where a null TablePtr would crash the application.

Fixed crash sites

File Function Risk
sqlitetablemodel.cpp:134 setQuery() Primary crash site - null deref on ->isView() and ->fields
TableBrowser.cpp:899 applyViewportSettings() Null deref on ->isView()
TableBrowser.cpp:992 generateFilters() Null deref in getFieldNumber()
TableBrowser.cpp:1450 editDisplayFormat() Null deref on ->fields.at()
TableBrowser.cpp:1551 copyColumnName() Null deref on ->fields.at()
sqlitedb.cpp:1336 getRow() Null deref on ->rowidColumns()
sqlitedb.cpp:1378 max() Null deref on ->primaryKeyColumns()
sqlitedb.cpp:1792 alterTable() Null deref on *getTableByName(...)

Fixes #4110

mdmahendri and others added 14 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.
When a table name stored in sqlite_master differs in case from the name
in the CREATE TABLE statement (e.g. databases created by Turso), the
getTableByName lookup could return a null TablePtr. Multiple call sites
dereferenced the result without checking for null, causing SIGSEGV
crashes.

This complements the case-insensitive lookup fix (commit 222e430) by
adding defensive null checks at all remaining unprotected call sites in
the browse data path and related operations.

Fixes sqlitebrowser#4110
@rachavz rachavz force-pushed the fix/null-checks-table-lookup branch from 9bc0dc4 to f6242b6 Compare April 1, 2026 13:35
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]: SIGSEGV: Address boundary error when trying to view table data

4 participants