-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Description
When importing a shortcut that contains an empty or whitespace-only CustomOutputName or OutputName, the decompiler crashes with a panic.
Environment
- Cherri version: v2.1.0
- OS: macOS (arm64)
- Installation: Homebrew
Steps to Reproduce
- Have a shortcut with an action that has
CustomOutputNameset to" "(single space) - Run
cherri --import=shortcut.shortcut
Error Output
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
main.capitalize({0x140001e061d?, 0x0?})
/Users/brandonjordan/cherri/main.go:244 +0x108
main.sanitizeIdentifier(0x1400003bcb0)
/Users/brandonjordan/cherri/decompile.go:283 +0x13c
main.mapUUID({0x140001e0621, 0x24}, {0x140001e061d, 0x1})
/Users/brandonjordan/cherri/decompile.go:273 +0x64
main.mapIdentifiers()
/Users/brandonjordan/cherri/decompile.go:86 +0x1b4
main.decompile({0x14000194000?, 0x102b47968?, 0x1030c045d?})
/Users/brandonjordan/cherri/decompile.go:57 +0x31c
main.main()
/Users/brandonjordan/cherri/main.go:95 +0x8e8
Root Cause Analysis
In main.go:244, the capitalize function assumes the input string is non-empty:
func capitalize(s string) string {
var char = s[0] // panics if s is empty
...
}When sanitizeIdentifier processes a whitespace-only string like " ":
strings.TrimSpace(" ")returns""strings.Split("", " ")returns[""]capitalize("")is called and panics
Suggested Fix
Add an empty string check in capitalize:
func capitalize(s string) string {
if len(s) == 0 {
return s
}
var char = s[0]
var after, _ = strings.CutPrefix(s, string(char))
return fmt.Sprintf("%c%s", unicode.ToUpper(rune(char)), after)
}Or in sanitizeIdentifier:
func sanitizeIdentifier(identifier *string) {
*identifier = strings.TrimSpace(*identifier)
if *identifier == "" {
*identifier = "Unnamed"
return
}
// ... rest of the function
}Additional Issue
After fixing the empty name issue, another panic occurs in decompAttachmentString:
panic: runtime error: index out of range [17] with length 11
goroutine 1 [running]:
main.decompAttachmentString(...)
/Users/brandonjordan/cherri/decompile.go:1059 +0x43c
This appears to be related to string index calculations with attachments.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels