Skip to content

BUG: sanitizeFilename truncates by bytes, can produce invalid UTF-8 #1102

@andrinoff

Description

@andrinoff

Describe the bug

main.go:2808-2815:

const maxFilenameLen = 255
if len(name) > maxFilenameLen {
    ext := filepath.Ext(name)
    ...
    name = name[:maxFilenameLen-len(ext)] + ext
}

The slice cuts at byte boundaries. If the filename is multi-byte UTF-8 (CJK, emoji, accented letters) the cut can land mid-rune, producing an invalid UTF-8 filename — which several filesystems then reject or display as ?.

Expected behavior

Trim by rune boundary using utf8.DecodeLastRuneInString so the last rune is whole.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions