Keep changing the notes folder from crashing the notes list - #34
Merged
Merged
Conversation
Changing the notes folder replaces the library under every open browser window. -[NotesTableView viewingLocation] bounded its lookup with [self numberOfRows], the table's cached row count, and then indexed the data source's backing array with it. During the replacement the table holds a fresh data source while that cached count still describes the previous library. -[FastListDataSource fillArrayFromArray:] only allocates its backing array when the new count exceeds the old one, so a data source that has never held a row returns NULL from -immutableObjects. Indexing it crashed with EXC_BAD_ACCESS at address 0x0. Measured at the crash: immutableObjects NULL, [self numberOfRows] 1, [[self dataSource] count] 0. Bound the lookup by the data source's own count and skip it when the backing array is absent. Claude-Session: https://claude.ai/code/session_01W5dVNP811hKcLKUmJHD1FG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Changing the notes folder in Preferences crashed the app with
EXC_BAD_ACCESSat address0x0.Cause
-viewingLocationbounded its lookup with the table's cached row count and then indexed the data source's backing array with it:Changing the notes folder replaces the library under every open browser window.
-attachLibrary:finishingOldLibrary:installs a fresh data source, and the refresh runs while the table's cached count still describes the previous library.The NULL is legitimate rather than corruption:
-[FastListDataSource fillArrayFromArray:]only allocatesobjectswhencount > oldArraySize, so a data source that has never held a row keeps it NULL and-immutableObjectsreturns that.Measured in lldb at the crash:
[[self dataSource] immutableObjects]0x0[self numberOfRows]1(stale)[[self dataSource] count]0So the guard passed on a stale count and dereferenced
NULL[0].This is why direction matters: switching to an empty folder is survivable, while switching back is when a never-populated data source meets a non-zero cached count.
Fix
Bound the lookup by the data source's own count, and skip it when the backing array is absent.
Testing
New suite
Tests/Regression/library-switch/, registered inTests/run-regression-tests.py(14 checks):Reverting the guard and rebuilding crashes the suite (exit 245,
SIGSEGV) at the switch back, so the check cannot pass vacuously.The stale-count window cannot be staged directly, because
-setDataSource:invalidates the table's cached row count — I tried, and the synthetic precondition failed to hold. It opens only during a real library switch, so the suite drives the switch end to end through thesetAliasDataForDefaultDirectory:sender:default that the Preferences "Other..." item writes.Ran on macOS 13.7.8, Intel Development build. Independent of #33.
https://claude.ai/code/session_01W5dVNP811hKcLKUmJHD1FG