Skip to content

Guard file browser back and forward against leaving the history - #166

Merged
dayglojesus merged 1 commit into
mainfrom
fix/file-browser-history-bounds
Oct 27, 2026
Merged

dayglojesus merged 1 commit into
mainfrom
fix/file-browser-history-bounds

Conversation

@dayglojesus

Copy link
Copy Markdown
Collaborator

Summary

⌘← and ⌘→ in the file browser crash the app when there is nowhere to go. FileBrowserOutlineView sends goBack:/goForward: straight to the controller from its key equivalent handler (FileBrowserOutlineView.mm:70-71), and the two actions stepped historyIndex unconditionally (FileBrowserViewController.mm:298-299). setHistoryIndex: then indexed the history array at -1 or at its count, threw NSRangeException, and the exception handler aborted the process. The menu items, header buttons and swipe gesture were already guarded through validateMenuItem:, the canGoBack/canGoForward bindings and the gesture handler; only the keyboard path was not. Inherited from upstream (a304ebe).

Reproduced on 2.6.1-undead: open a project, click in the file browser, press ⌘←.

The two session-restore sites clamped the saved index to count rather than count - 1, which lands one past the last entry with the same exception.

Change

  • goBack: and goForward: do nothing unless canGoBack / canGoForward.
  • Both restore clamps use count - 1.
  • New Frameworks/FileBrowser/tests/t_history_navigation.mm: back with no history, forward with no history, restored index past the end.

Tests

The three new tests failed before the change with the crash report's exception (index 18446744073709551615 beyond bounds for empty array, index 1 beyond bounds for empty array, index 1 beyond bounds [0 .. 0]). After it, FileBrowser_tests --no-parallel passes 8 of 8. The fix was also confirmed in a Debug build of this branch: ⌘← and ⌘→ in a fresh window do nothing.

Changelog

File Browser: ⌘← and ⌘→ with nowhere to go no longer crash the app.

⌘← and ⌘→ in the file browser send goBack:/goForward: straight from
FileBrowserOutlineView’s key equivalent handler, with no menu validation
in between. The actions stepped the history index unconditionally, so
pressing either key with nowhere to go indexed the history array at -1
or at its count, threw NSRangeException, and the exception handler
aborted the app. Every other route (menu, header buttons, swipe) was
already guarded.

The two session-restore sites also clamped the saved index to count
rather than count - 1, which lands one past the last entry.

goBack:/goForward: now check canGoBack/canGoForward, the clamps use
count - 1, and t_history_navigation.mm covers all three cases. The
tests failed with the crash’s exception before the change.
@dayglojesus
dayglojesus merged commit 47b4f0b into main Oct 27, 2026
3 checks passed
@dayglojesus
dayglojesus deleted the fix/file-browser-history-bounds branch October 27, 2026 03:03
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.

1 participant