Skip to content

Commit 0f10a3a

Browse files
committed
Code Quality: Add index validation in navigation toolbar handler
Prevents out-of-range access by validating the index before accessing PathComponents in the navigation toolbar click handler.
1 parent 2c522c7 commit 0f10a3a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Files.App/UserControls/NavigationToolbar.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,17 @@ private async void BreadcrumbBar_ItemClicked(Controls.BreadcrumbBar sender, Cont
274274
return;
275275
}
276276

277+
// Validate index before accessing the collection
278+
if (args.Index < 0 || args.Index >= ViewModel.PathComponents.Count)
279+
return;
280+
277281
// Navigation to the current folder should not happen
278282
if (args.Index == ViewModel.PathComponents.Count - 1 ||
279283
ViewModel.PathComponents[args.Index].Path is not { } path)
280284
return;
281285

282286
// If user clicked the item with middle mouse button, open it in new tab
283287
var openInNewTab = args.PointerRoutedEventArgs?.GetCurrentPoint(null).Properties.PointerUpdateKind is PointerUpdateKind.MiddleButtonReleased;
284-
285288
await ViewModel.HandleFolderNavigationAsync(path, openInNewTab);
286289
}
287290

0 commit comments

Comments
 (0)