{"record":{"id":"6c4e0918b5662463","repo":"pion/webrtc","slug":"w-payload-too-short-for-comment-len-d","errorCode":null,"errorMessage":"%w: payload too short for comment len %d","messagePattern":"%w: payload too short for comment len (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggreader/oggreader.go","lineNumber":466,"sourceCode":"\n\tpos := vendorEnd + u32Size\n\tuserComments := make([]UserComment, userCommentCount)\n\n\tfor i := range userComments {\n\t\tcomment, nextPos, err := parseSingleUserComment(payload, pos, u32Size, i)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tuserComments[i] = comment\n\t\tpos = nextPos\n\t}\n\n\treturn userComments, nil\n}\n\nfunc parseSingleUserComment(payload []byte, pos, u32Size, index int) (UserComment, int, error) {\n\tif pos+u32Size > len(payload) {\n\t\treturn UserComment{}, 0, fmt.Errorf(\"%w: payload too short for comment len %d\", errBadOpusTagsSignature, index)\n\t}\n\n\tcommentLen32 := binary.LittleEndian.Uint32(payload[pos : pos+u32Size])\n\tpos += u32Size\n\n\tcommentLen := int(commentLen32)\n\tif commentLen < 0 || pos+commentLen > len(payload) {\n\t\treturn UserComment{}, 0, fmt.Errorf(\"%w: payload too short for comment %d\", errBadOpusTagsSignature, index)\n\t}\n\n\tcomment := string(payload[pos : pos+commentLen])\n\tpos += commentLen\n\n\tparts := strings.SplitN(comment, \"=\", 2)\n\tif len(parts) != 2 {\n\t\treturn UserComment{}, 0, fmt.Errorf(\"%w: invalid comment %d\", errBadOpusTagsSignature, index)\n\t}\n","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggreader/oggreader.go#L448-L484","documentation":"Returned by parseSingleUserComment when there are not enough bytes left in the payload to even read the 4-byte (u32Size) length prefix of the comment at the given index. This means the declared comment count promised more comments than the payload actually contains, so the OpusTags packet is truncated or corrupt.","triggerScenarios":"Parsing an OpusTags payload where, after the vendor string and comment count, fewer than u32Size bytes remain at the current cursor while iterating over the declared number of comments.","commonSituations":"Truncated Ogg Opus files from interrupted transfers, corrupted metadata segments, packets cut off at page boundaries, or files written by buggy encoders that overstate the comment count.","solutions":["Check the file is not truncated (compare against source size; re-download/re-copy the file).","Re-encode or rewrite the OpusTags metadata with a reliable tool to fix the comment count.","Handle the error via errors.Is(err, errBadOpusTagsSignature) and skip or quarantine the malformed file.","If processing streams, ensure you feed the complete OpusTags packet, not a page fragment."],"exampleFix":"// before: feeding partial page data\ncomments, err := ParseOpusTags(partialPageData)\n// after: assemble the full OpusTags packet first\nfullPacket := concatenateOggPages(opusTagsPacket)\ncomments, err := ParseOpusTags(fullPacket)","handlingStrategy":"validation","validationCode":"func isCompleteOpusTagsPacket(packet []byte) bool {\n    if len(packet) < 8 { return false }\n    vendorLen := int(binary.LittleEndian.Uint32(packet[8:12]))\n    return len(packet) >= 12+vendorLen+4 // magic + vendorLen + vendor + commentCount\n}","typeGuard":null,"tryCatchPattern":"comments, err := ParseOpusTags(packet)\nif err != nil {\n    if errors.Is(err, errBadOpusTagsSignature) {\n        return nil, fmt.Errorf(\"truncated or corrupt OpusTags packet: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Assemble the full OpusTags packet from Ogg pages before parsing; don't parse page fragments.","Check file completeness (size, Ogg EOS flag) before metadata parsing.","Handle interrupted transfers by validating input before ingest.","Treat errBadOpusTagsSignature errors as permanent input defects, not retryable."],"tags":["go","ogg","opus","truncated-payload","malformed-header"],"backgroundTag":"invalid-opus-tags-header","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"}