fix(history): don't panic when a listing filters down to nothing - #634
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
fix(history): don't panic when a listing filters down to nothing#634NgoQuocViet2001 wants to merge 1 commit into
NgoQuocViet2001 wants to merge 1 commit into
Conversation
create_dirlist_with_history clamps every index carried over from the previous listing into the new one, but the visual-mode anchor did it with `contents_len - 1` and nothing guarded contents_len == 0. A directory whose entries are all filtered out reaches exactly that, and usize subtraction overflows: thread '...' panicked at src/history.rs:117:21: attempt to subtract with overflow Toggling hidden files off over a directory that holds only dotfiles, with visual mode on, is enough. An empty listing has no anchor, so return None. The cursor index in the same block read `dirlist.contents[i]`, where `i` is the previous listing's stored index. Nothing keeps that index in step with its own contents — set_index does not bound it — so a stale one indexes out of range. Read it with .get() instead; the name lookup it feeds is only a hint, and without it `i` still lands in range, having passed the arm above.
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.
Likely the crash behind #614 — the reports there are exit code 101 after
toggle_hidden, and a commenter narrowed it to dotfiles being present.The panic
create_dirlist_with_historyclamps every index carried over from the previous listing into the new one. The cursor index and the viewport index both checkcontents_len == 0first. The visual-mode anchor does not:A directory whose entries are all filtered out gives
contents_len == 0, and the subtraction overflows. Toggling hidden files off over a directory holding only dotfiles, with visual mode on, is enough to reach it:An empty listing has nowhere for an anchor to point, so it returns
None.The index read next to it
The cursor branch reads
&dirlist.contents[i], whereiis the previous listing's stored index. Nothing keeps that index in step with its own contents —set_indextakes anOption<usize>and does not bound it — so a stale one indexes out of range on a listing that is otherwise fine.It now reads through
.get(i). The entry is only used to look the old file name up in the new contents, and when that lookup is unavailableiis still returned, exactly as before — it has already passed thei >= contents_lenarm above. No behaviour changes for an index that is in range.Test plan
cargo test— 43 passed, 0 failed (41 pre-existing + 2 new).attempt to subtract with overflowshown above, and passes with the change.cargo test); theallmytoesdependency does not compile on Windows.Note on #614
I could not reproduce the reporter's exact keystroke sequence, so I would not close #614 on this alone — but this is a real panic on the same code path, with the same exit code, and reached by the same command. Happy to keep digging if it survives.