{"record":{"id":"51141b71aee6d881","repo":"pion/webrtc","slug":"w-user-comment-is-too-long","errorCode":null,"errorMessage":"%w: user comment is too long","messagePattern":"%w: user comment is too long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":814,"sourceCode":"func 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}\n\n\treturn nil\n}\n\nfunc isValidCommentName(comment string) bool {\n\tif comment == \"\" {","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L796-L832","documentation":"This error is returned by validateUserComment when a single OpusTags user comment (NAME=value) cannot be represented in the Ogg OpusTags header because its total encoded length — comment name length + 1 separator byte + value length — exceeds maxUint32Length (0xFFFFFFFF). The OpusComments spec stores each comment with a 32-bit little-endian length prefix, so a combined size larger than a uint32 cannot be serialized. It is wrapped by errInvalidOpusTags, which the caller can check with errors.Is.","triggerScenarios":"Calling any API that validates OpusTags (e.g. OpusTags validation via validateOpusTags / oggwriter paths that serialize the comment header) with a UserComment whose len(comment.Comment)+1+len(comment.Value) > 4294967295 bytes. In practice this requires a comment name or value of multiple gigabytes.","commonSituations":"Programmatically generating enormous metadata (e.g. embedding a huge base64 blob, cover art data, or a giant JSON payload as a comment value) instead of referencing it externally; unit tests pushing boundary sizes; a bug concatenating values repeatedly into one comment.","solutions":["Shorten the comment name or value so that len(name)+1+len(value) <= 4294967295 bytes (in Go, byte length of the strings).","Move large payloads (cover art, lyrics blobs) out of OpusTags metadata into a separate sidecar file or stream.","Add a pre-flight check on UserComment sizes before constructing the OpusTags struct to fail early with a clearer message.","If errors.Is(err, errInvalidOpusTags) matches, log which comment is oversized; the error does not name it."],"exampleFix":"// before\ntags := oggwriter.OpusTags{UserComments: []oggwriter.UserComment{\n  {Comment: \"COVERART\", Value: string(hugeBase64Blob)}, // > 4 GiB\n}}\n// after\nif len(\"COVERART\")+1+len(hugeBase64Blob) > math.MaxUint32 {\n  return errors.New(\"cover art too large for OpusTags; write sidecar file instead\")\n}\ntags := oggwriter.OpusTags{UserComments: []oggwriter.UserComment{\n  {Comment: \"COVERART_FILE\", Value: \"cover.jpg\"},\n}}","handlingStrategy":"validation","validationCode":"func validateCommentSize(name, value string) error {\n\tif uint64(len(name))+1+uint64(len(value)) > math.MaxUint32 {\n\t\treturn fmt.Errorf(\"user comment %q too long: %d bytes\", name, len(name)+1+len(value))\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := writer.WriteOpusTags(tags); err != nil {\n\tif errors.Is(err, oggwriter.ErrInvalidOpusTags) {\n\t\t// trim or drop oversized comments, then retry\n\t}\n\treturn err\n}","preventionTips":["Cap comment name and value lengths at application level (e.g. 4 KiB) well below the uint32 limit.","Never embed large blobs (cover art, binary) in OpusTags comments; reference them by path or URL.","Validate all UserComment entries in a loop before handing OpusTags to the writer."],"tags":["go","ogg","opus","metadata","validation","size-limit"],"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"}