Skip to content

Decompile crash: panic on empty or whitespace-only CustomOutputName/OutputNameΒ #145

@tagomorisatoshi

Description

@tagomorisatoshi

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

  1. Have a shortcut with an action that has CustomOutputName set to " " (single space)
  2. 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 " ":

  1. strings.TrimSpace(" ") returns ""
  2. strings.Split("", " ") returns [""]
  3. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions