From 53868ef4e1475f2231785e38ab80bc494131b82a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 24 Oct 2023 14:21:11 +0100 Subject: [PATCH] ncdu: fix crash when re-entering changed directory after rescan ncdu stores the position that it was in for each directory. However doing a rescan can cause those positions to be out of range if the number of files decreased in a directory. When re-entering the directory, this causes an index out of range error. This fixes the problem by detecting the index out of range and flushing the saved directory position. See: https://forum.rclone.org/t/slice-bounds-out-of-range-during-ncdu/42492/ --- cmd/ncdu/ncdu.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/ncdu/ncdu.go b/cmd/ncdu/ncdu.go index 0482a71c0..cde48d972 100644 --- a/cmd/ncdu/ncdu.go +++ b/cmd/ncdu/ncdu.go @@ -386,6 +386,12 @@ func (u *UI) Draw() { } showEmptyDir := u.hasEmptyDir() dirPos := u.dirPosMap[u.path] + // Check to see if a rescan has invalidated the position + if dirPos.offset >= len(u.sortPerm) { + delete(u.dirPosMap, u.path) + dirPos.offset = 0 + dirPos.entry = 0 + } for i, j := range u.sortPerm[dirPos.offset:] { entry := u.entries[j] n := i + dirPos.offset