{"record":{"id":"debc986df9005be1","repo":"pion/webrtc","slug":"w-payload-too-short-for-comment-d","errorCode":null,"errorMessage":"%w: payload too short for comment %d","messagePattern":"%w: payload too short for comment (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggreader/oggreader.go","lineNumber":474,"sourceCode":"\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\n\treturn UserComment{\n\t\tComment: parts[0],\n\t\tValue:   parts[1],\n\t}, pos, nil\n}\n","sourceCodeStart":456,"sourceCodeEnd":490,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggreader/oggreader.go#L456-L490","documentation":"Returned by parseSingleUserComment when the comment's declared length (a little-endian uint32, negative as int if > MaxInt64-style overflow on 32-bit) exceeds the remaining payload bytes, or is negative. The payload cannot contain the full comment body, indicating a corrupt or truncated OpusTags packet.","triggerScenarios":"Parsing an OpusTags payload where the length prefix of comment N, once read, points past the end of the payload (pos+commentLen > len(payload)) or underflows to a negative int.","commonSituations":"Corrupted metadata from bad disk sectors or interrupted downloads, maliciously crafted files with huge comment lengths (denial-of-service vectors), or encoders writing inconsistent length fields.","solutions":["Verify file integrity (checksum) and obtain an uncorrupted copy.","Reject untrusted files: treat errors.Is(err, errBadOpusTagsSignature) as invalid input rather than retrying.","Sanitize the file with a metadata tool (opustags, ffmpeg) to rewrite consistent comment lengths.","If building the payload yourself, ensure each comment's length prefix matches the actual comment bytes written."],"exampleFix":"// before: trusting a corrupt file's length field\ncomments, err := ParseOpusTags(corruptPayload)\n// after: guard against oversized declared lengths before parsing\nmaxLen := len(payload) - pos\nif declaredLen > maxLen { return errors.New(\"comment length exceeds payload\") }\ncomments, err := ParseOpusTags(payload)","handlingStrategy":"validation","validationCode":"func commentLengthsInBounds(payload []byte, vendorEnd, u32Size int) bool {\n    pos := vendorEnd + u32Size\n    for pos+u32Size <= len(payload) {\n        l := int(binary.LittleEndian.Uint32(payload[pos : pos+u32Size]))\n        pos += u32Size\n        if l < 0 || pos+l > len(payload) { return false }\n        pos += l\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":"comments, err := ParseOpusTags(payload)\nif err != nil {\n    if errors.Is(err, errBadOpusTagsSignature) {\n        return nil, fmt.Errorf(\"comment length exceeds payload; rejecting file: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Reject untrusted files with implausibly large declared comment lengths — they are a DoS/corruption vector.","Verify checksums or re-download when corruption is suspected.","Cap accepted payload sizes before parsing.","If writing OpusTags yourself, serialize length prefixes from the actual comment bytes, never from user-supplied lengths."],"tags":["go","ogg","opus","buffer-overrun","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"}