Skip to content

fix: prevent nil pointer crash when extracting with no current node#706

Open
ricardbejarano wants to merge 1 commit into
wagoodman:mainfrom
bejaratommy:fix-extractfile-nil-crash
Open

fix: prevent nil pointer crash when extracting with no current node#706
ricardbejarano wants to merge 1 commit into
wagoodman:mainfrom
bejaratommy:fix-extractfile-nil-crash

Conversation

@ricardbejarano

Copy link
Copy Markdown

What

extractFile (the Ctrl+E action in the file tree view) called node.Path() on the result of CurrentNode(...) without checking for nil. When there is no node at the current cursor position — for example when an active filter matches nothing — CurrentNode returns nil and dive segfaults:

panic: runtime error: invalid memory address or nil pointer dereference
github.com/wagoodman/dive/dive/filetree.(*FileNode).Path(...)
	dive/filetree/file_node.go:276
github.com/wagoodman/dive/runtime/ui/view.(*FileTree).extractFile(...)
	runtime/ui/view/filetree.go:321

Fix

Guard against a nil node and return early, matching the existing pattern already used by the viewmodel's navigation methods (e.g. CursorLeft), which all bail out when getAbsPositionNode returns nil.

Notes

Fixes #620 (reproduced and confirmed independently by another user in the issue thread). The change is a localized nil check; the affected view package has no unit tests (the views depend on a live gocui runtime), so I relied on CI for verification.

extractFile called node.Path() without checking whether CurrentNode
returned nil, segfaulting when there is no node at the cursor position
(e.g. an active filter matches nothing). Guard against a nil node and
return early, matching the existing pattern in the viewmodel's
CursorLeft and similar navigation methods.

Fixes wagoodman#620

Signed-off-by: bejaratommy <tommy@bejara.net>
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.

Crash when extracting a file

2 participants