Skip to content

fix(dir): report an error instead of panicking when the path is missing - #1660

Open
NUAAwqy wants to merge 1 commit into
apache:mainfrom
NUAAwqy:fix/dir-dirsize-panics-on-missing-path
Open

NUAAwqy wants to merge 1 commit into
apache:mainfrom
NUAAwqy:fix/dir-dirsize-panics-on-missing-path

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Oct 30, 2026

Copy link
Copy Markdown

Fixes #

Proposed Changes

  • pkg/dir.DirSize now checks the error its filepath.Walk callback is given before it uses the FileInfo. filepath.Walk passes a nil info when the root cannot be stat-ed, so a missing path used to raise invalid memory address or nil pointer dereference instead of returning the error.
  • The admin dashboard's calculateStorage (internal/service/dashboard/dashboard_service.go:334) already logs and swallows an error from DirSize; with the panic that branch was unreachable, so a missing or unmounted upload directory turned the dashboard into a crash rather than an empty size.
  • Adds pkg/dir/dir_test.go: the happy path plus three missing-path cases that must return an error and must not panic.

Additional Info

Reproducer on main (6744295): dir.DirSize("/no/such/dir") panics with SIGSEGV at
pkg/dir/dir.go:45. After the change it returns the lstat …: no such file or directory
error. No new dependency; golangci-lint v2.6.2 (make lint) and go mod tidy are clean.

DirSize ignores the error its filepath.Walk callback is handed. When the
root cannot be stat-ed, filepath.Walk calls the callback with a nil
FileInfo, so info.IsDir() dereferences nil and the process panics.

This is reachable from the admin dashboard: calculateStorage walks
serviceConfig.UploadPath and explicitly logs and swallows the error it
expects back, so a missing or unmounted upload directory turns the
request into a panic instead of the intended "size unknown" path.

Handle the callback error before touching info.

This branch has not been deployed

No deployments
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.

1 participant