pion/webrtc · error
%w: too many user comments
Error message
%w: too many user comments
What it means
OpusTags comment count is stored in a uint32 field in the comment header, so the number of user comments cannot exceed maxUint32Length (math.MaxUint32). validateOpusTagsWithMaxHeaderLen returns this wrapped errInvalidOpusTags when len(UserComments) exceeds that bound. In practice it guards against corrupted or hostile tag sets producing an unencodable header.
Source
Thrown at pkg/media/oggwriter/oggwriter.go:768
if err := validateUserComments(comments); err != nil {
return err
}
opusTags.UserComments = append(opusTags.UserComments, comments...)
return nil
}
func validateOpusTags(opusTags OpusTags) error {
return validateOpusTagsWithMaxHeaderLen(opusTags, uint64(math.MaxInt))
}
func validateOpusTagsWithMaxHeaderLen(opusTags OpusTags, maxHeaderLen uint64) error {
if err := validateOpusTagString("vendor", opusTags.Vendor); err != nil {
return err
}
if uint64(len(opusTags.UserComments)) > maxUint32Length {
return fmt.Errorf("%w: too many user comments", errInvalidOpusTags)
}
if err := validateUserComments(opusTags.UserComments); err != nil {
return err
}
return validateOpusTagsHeaderLen(opusTags, maxHeaderLen)
}
func validateOpusTagsHeaderLen(opusTags OpusTags, maxHeaderLen uint64) error {
headerLen := uint64(len(commentPageSignature)) + 4 + uint64(len(opusTags.Vendor)) + 4
if headerLen > maxHeaderLen {
return fmt.Errorf("%w: header is too long", errInvalidOpusTags)
}
for _, comment := range opusTags.UserComments {
userCommentLen := uint64(len(comment.Comment)) + 1 + uint64(len(comment.Value))
commentFieldLen := 4 + userCommentLenView on GitHub (pinned to 8c25dc09fa)
Solutions
- Trim the UserComments slice below 2^32 entries (realistically, to a few dozen).
- Stop accumulating comments: replace the slice rather than appending to the default tags.
- Deduplicate repeated tags (e.g. repeated TITLE/LANGUAGE entries) before validating.
- Check errors.Is(err, errInvalidOpusTags) to identify tag validation failures.
Example fix
// before
for i := 0; i < 5000000000; i++ { tags.UserComments = append(tags.UserComments, c) }
// after
if uint64(len(tags.UserComments)) + uint64(len(newComments)) <= maxUint32Length { tags.UserComments = append(tags.UserComments, newComments...) } Defensive patterns
Strategy: validation
Validate before calling
if uint64(len(tags.UserComments)) > 1<<32-1 { return errors.New("too many user comments") } Try / catch
if err := writer.SetOpusTags(tags); err != nil {
if errors.Is(err, errInvalidOpusTags) { /* drop excess comments and retry */ }
return err
} Prevention
- Cap comment count to a sane number (tens, not billions)
- Replace UserComments instead of unbounded appends
- Deduplicate repeated tag keys before applying
- Validate tags loaded from untrusted media before reuse
When it happens
Trigger: Calling the OpusTags validation path (e.g. via newTrackConfig or a SetOpusTags-style API) with an OpusTags value whose UserComments slice is longer than 4,294,967,295 entries.
Common situations: Programmatically appending comments in a loop without bound (applyUserComments appends, so repeated calls accumulate); loading a pre-existing OpusTags blob from untrusted media and passing it through unchanged.
Related errors
- %w: header is too long
- %w: invalid user comment name
- %w: user comment is too long
- %w: %s is too long
- %w: invalid comment %d
AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03).
Data as JSON: /api/errors/b2cc7fb49e201c73.
Report an issue: GitHub.