Skip to content

Fix crash on startup when a session file cannot be read - #1123

Merged
dail8859 merged 1 commit into
dail8859:masterfrom
hemanpa:fix/845-session-load-null-guards
Sep 12, 2026
Merged

dail8859 merged 1 commit into
dail8859:masterfrom
hemanpa:fix/845-session-load-null-guards

Conversation

@hemanpa

@hemanpa hemanpa commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

ScintillaNext::fromFile() returns a null pointer when the file cannot be read from
disk, but SessionManager used the returned pointer without checking it.

If a session references a file that still exists but cannot be opened — for example
after macOS resets folder access permissions following an upgrade — the null pointer
is dereferenced in EditorManager::setupEditor() and the application crashes during
startup, before the main window is shown. It then crashes on every subsequent launch,
leaving no way to recover other than deleting the settings.

This guards the three fromFile() call sites so an unreadable file is skipped and a
warning logged, which is what EditorManager::createEditorFromFile() already does.

It also guards the two findChild<BookMarkDecorator*>() results, which can also
return null — that is the code path in the crash log attached to the issue.

Testing

macOS 26.6, Qt 6.11.2, Debug build. Created a session referencing a chmod 000 file:

  • Before: EXC_BAD_ACCESS (code=1, address=0x0) at
    ScintillaEdit::clearCmdKey(this=0x0, keyDefinition=309)
  • After: the application starts, logs
    could not be read from disk, ignoring this file for session loading,
    and skips the file

Also verified a readable session file still restores normally, including bookmarks
round-tripping correctly through save and load.

Fixes #845

ScintillaNext::fromFile() returns a null pointer when the file cannot be
read from disk, but SessionManager used the returned pointer without
checking it. A session referencing a file that exists but cannot be
opened, for example after macOS resets folder access permissions
following an upgrade, dereferenced the null pointer in
EditorManager::setupEditor() and crashed the application during startup
before the main window was shown. This happened on every launch, leaving
no way to recover other than deleting the settings.

Guard the three fromFile() call sites so an unreadable file is skipped
and a warning is logged, which is what EditorManager::createEditorFromFile()
already does.

Also guard the two findChild<BookMarkDecorator*>() results, which can
also return null.

Fixes dail8859#845
@hemanpa

hemanpa commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Heads up on the two failing checks — I believe both are pre-existing on master
rather than caused by this change:

  • Check for spelling errors: alot in a comment at src/dialogs/MainWindow.cpp:742,
    introduced in b4c6f51. This check has been failing on master for the last few
    commits. This PR only touches src/SessionManager.cpp. Opened Fix spelling error in zoom out comment #1124 to fix the typo
    separately.
  • build (macos-latest, 6.5) and (macos-latest, 6.8): both also fail on master
    (macOS 6.10, all Ubuntu and all Windows jobs pass). Looks related to what Improve MacOS build #1119 is
    addressing.

Everything that currently passes on master also passes here.

@dail8859 dail8859 linked an issue Sep 12, 2026 that may be closed by this pull request
@dail8859 dail8859 added the macos Related specifically to macOS label Sep 12, 2026
@dail8859
dail8859 merged commit 1014c2a into dail8859:master Sep 12, 2026
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macos Related specifically to macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MacOS upon open denying access to XYZ folder causes crash Corrupt session causes application to not load

2 participants