{"record":{"id":"644d7b489689a51c","repo":"pion/webrtc","slug":"w-invalid-user-comment-name","errorCode":null,"errorMessage":"%w: invalid user comment name","messagePattern":"%w: invalid user comment name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":808,"sourceCode":"\t\theaderLen += commentFieldLen\n\t}\n\n\treturn nil\n}\n\nfunc validateUserComments(comments []UserComment) error {\n\tfor _, comment := range comments {\n\t\tif err := validateUserComment(comment); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc validateUserComment(comment UserComment) error {\n\tif !isValidCommentName(comment.Comment) {\n\t\treturn fmt.Errorf(\"%w: invalid user comment name\", errInvalidOpusTags)\n\t}\n\tif err := validateOpusTagString(\"user comment value\", comment.Value); err != nil {\n\t\treturn err\n\t}\n\tif uint64(len(comment.Comment))+1+uint64(len(comment.Value)) > maxUint32Length {\n\t\treturn fmt.Errorf(\"%w: user comment is too long\", errInvalidOpusTags)\n\t}\n\n\treturn nil\n}\n\nfunc validateOpusTagString(field, value string) error {\n\tif !utf8.ValidString(value) {\n\t\treturn fmt.Errorf(\"%w: %s is not valid UTF-8\", errInvalidOpusTags, field)\n\t}\n\tif uint64(len(value)) > maxUint32Length {\n\t\treturn fmt.Errorf(\"%w: %s is too long\", errInvalidOpusTags, field)\n\t}","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L790-L826","documentation":"Opus comment names must be printable ASCII (0x20-0x7D) excluding '=' and non-empty, per the Ogg Opus comment header spec. validateUserComment returns this wrapped errInvalidOpusTags when isValidCommentName rejects the comment's name (the part before '=').","triggerScenarios":"Creating a UserComment with an empty Comment field, a name containing '=', a control character (<0x20), or a byte >= 0x7E (including non-ASCII UTF-8 names like 'TITELÄ' or emoji names) and passing it through applyUserComments / the tags validation path.","commonSituations":"Localizing tag names to non-ASCII languages; accidentally including the full 'NAME=value' string in the Comment field so the '=' lands in the name; names built from untrusted or machine-generated input containing tabs/newlines.","solutions":["Use ASCII printable names without '=', 0x20-0x7D only, non-empty (e.g. TITLE, ARTIST, DESCRIPTION).","Split 'NAME=value' strings into the Comment (name) and Value fields instead of embedding '=' in the name.","Uppercase and sanitize the name (strip control/non-ASCII bytes) before adding the comment.","Validate locally: name != \"\" and each byte b in 0x20..0x7D and b != '='."],"exampleFix":"// before\nUserComment{Comment: \"TITLE=Song\", Value: \"x\"} // '=' inside name\n// after\nUserComment{Comment: \"TITLE\", Value: \"Song\"}","handlingStrategy":"validation","validationCode":"func validCommentName(name string) bool {\n    if name == \"\" { return false }\n    for i := 0; i < len(name); i++ {\n        b := name[i]\n        if b < 0x20 || b > 0x7d || b == '=' { return false }\n    }\n    return true\n}","typeGuard":"func isASCIICommentName(s string) bool {\n    if s == \"\" { return false }\n    for i := 0; i < len(s); i++ { b := s[i]; if b < 0x20 || b > 0x7d || b == '=' { return false } }\n    return true\n}","tryCatchPattern":"if err := writer.SetOpusTags(tags); err != nil {\n    if errors.Is(err, errInvalidOpusTags) && strings.Contains(err.Error(), \"invalid user comment name\") {\n        // sanitize or drop offending comment\n    }\n    return err\n}","preventionTips":["Use standard uppercase ASCII tag names (TITLE, ARTIST, ...)","Never put '=' in the name; split NAME=value properly","Reject/sanitize control and non-ASCII bytes in names","Validate comments at construction time, not at write time"],"tags":["go","opus","opus-tags","metadata","validation"],"backgroundTag":"invalid-opus-tags","analyzedSha":"8c25dc09fa9e7c09aac4309ead88093d760432b0","analyzedAt":"2026-09-03T21:56:56.182Z","contentChangedAt":"2026-09-03T21:56:56.182Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}