1
8
Fork
You've already forked nup
0

nup update crashed when cleaning -force-glob #140

Closed
opened 2026年03月16日 03:57:14 +01:00 by derat · 2 comments
Owner
Copy link

I saw a crash that I don't understand while running nup update -require-covers today:

panic: runtime error: slice bounds out of range [18:17]
goroutine 1 [running]:
codeberg.org/derat/nup/cmd/nup/update.(*Command).Execute(0xc000190900, {0xc000124170?, 0x7fa6ea4c45c0?}, 0xc00043ab60, {0xc00035b1f0?, 0x10?, 0xe183c1?})
	.../nup/cmd/nup/update/command.go:169 +0x17d0
github.com/google/subcommands.(*Commander).Execute(0xc00017a000, {0xf41ef8, 0x15c6ac0}, {0x0, 0x0, 0x0})
	.../go/pkg/mod/github.com/google/subcommands@v1.2.0/subcommands.go:209 +0x37a
github.com/google/subcommands.Execute(...)
	.../go/pkg/mod/github.com/google/subcommands@v1.2.0/subcommands.go:492
main.main()
	.../nup/cmd/nup/main.go:57 +0x213e

I hadn't passed the -force-glob flag, and the same command worked when I ran it again.

I saw a crash that I don't understand while running `nup update -require-covers` today: ``` panic: runtime error: slice bounds out of range [18:17] goroutine 1 [running]: codeberg.org/derat/nup/cmd/nup/update.(*Command).Execute(0xc000190900, {0xc000124170?, 0x7fa6ea4c45c0?}, 0xc00043ab60, {0xc00035b1f0?, 0x10?, 0xe183c1?}) .../nup/cmd/nup/update/command.go:169 +0x17d0 github.com/google/subcommands.(*Commander).Execute(0xc00017a000, {0xf41ef8, 0x15c6ac0}, {0x0, 0x0, 0x0}) .../go/pkg/mod/github.com/google/subcommands@v1.2.0/subcommands.go:209 +0x37a github.com/google/subcommands.Execute(...) .../go/pkg/mod/github.com/google/subcommands@v1.2.0/subcommands.go:492 main.main() .../nup/cmd/nup/main.go:57 +0x213e ``` I hadn't passed the `-force-glob` flag, and the same command worked when I ran it again.
Author
Owner
Copy link

Here's the relevant code:

Lines 166 to 171 in 30d2b8d
// If forceGlob is already an absolute path or points into the music dir when resolved
// relative to the current dir, rewrite it to be relative to the music dir.
ifabs,err:=filepath.Abs(cmd.forceGlob);err==nil&&strutil.HasPathPrefix(abs,cmd.Cfg.MusicDir){
cmd.forceGlob=abs[len(cmd.Cfg.MusicDir)+1:]
log.Println("Rewrote -force-glob to",cmd.forceGlob)
}

filepath.Abs("") weirdly returns "/" instead of an error (undocumented), so I should probably only do this if the flag was actually set. The musicDir in my config is 17 characters long, so that's where the slice bounds came from. I still have no idea why the slice statement would've even executed, as strutil.HasPathPrefix("/", "/some/other/path") should be returning false.

Here's the relevant code: https://codeberg.org/derat/nup/src/commit/30d2b8dc3fc8310dcd55863edbf2650e92784f37/cmd/nup/update/command.go#L166-L171 `filepath.Abs("")` weirdly returns `"/"` instead of an error (undocumented), so I should probably only do this if the flag was actually set. The `musicDir` in my config is 17 characters long, so that's where the slice bounds came from. I still have no idea why the slice statement would've even executed, as `strutil.HasPathPrefix("/", "/some/other/path")` should be returning false.
Author
Owner
Copy link

I'm closing this for now, although I'm still not sure how it happened in the first case. :-/

I'm closing this for now, although I'm still not sure how it happened in the first case. :-/
Sign in to join this conversation.
No Branch/Tag specified
main
headless
picture
datastore
No results found.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
derat/nup#140
Reference in a new issue
derat/nup
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?