{"record":{"id":"acd96eabd17aa516","repo":"pion/webrtc","slug":"w-payload-too-short","errorCode":null,"errorMessage":"%w: payload too short","messagePattern":"%w: payload too short","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggreader/oggreader.go","lineNumber":413,"sourceCode":"\tvendor, vendorEnd, err := parseVendorString(payload, headerMagicLen, u32Size, minHeaderLen)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tuserComments, err := parseUserComments(payload, vendorEnd, u32Size)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &OpusTags{\n\t\tVendor:       vendor,\n\t\tUserComments: userComments,\n\t}, nil\n}\n\nfunc validateOpusTagsHeader(payload []byte, minHeaderLen int) error {\n\tif len(payload) < minHeaderLen {\n\t\treturn fmt.Errorf(\"%w: payload too short\", errBadOpusTagsSignature)\n\t}\n\n\tgot := HeaderType(payload[:8])\n\tif got != HeaderOpusTags {\n\t\treturn fmt.Errorf(\"%w: expected %q, got %q\", errBadOpusTagsSignature, HeaderOpusTags, got)\n\t}\n\n\treturn nil\n}\n\nfunc parseVendorString(payload []byte, headerMagicLen, u32Size, minHeaderLen int) (string, int, error) {\n\tvendorLen32 := binary.LittleEndian.Uint32(payload[headerMagicLen : headerMagicLen+u32Size])\n\tif int(vendorLen32) > len(payload)-minHeaderLen {\n\t\treturn \"\", 0, fmt.Errorf(\"%w: payload too short for vendor string\", errBadOpusTagsSignature)\n\t}\n\tvendorLen := int(vendorLen32)\n\n\tvendorStart := headerMagicLen + u32Size","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggreader/oggreader.go#L395-L431","documentation":"validateOpusTagsHeader returns this error when the payload handed to oggreader.ParseOpusTags is shorter than the minimum required OpusTags header length. The parser must read at least the 8-byte 'OpusTags' magic plus the vendor length field, so a truncated buffer cannot possibly be a valid tags header. The sentinel errBadOpusTagsSignature is wrapped so callers can match with errors.Is.","triggerScenarios":"Calling ParseOpusTags with a payload shorter than the minHeaderLen computed for it (e.g. fewer than ~12 bytes, magic + 4-byte vendor length); passing a packet slice cut short by a truncated Ogg page or an off-by-one range.","commonSituations":"Truncated/corrupt downloads of .opus files; slicing a reassembled Ogg stream incorrectly (dropping trailing bytes); parsing a comment header captured with a fixed-size buffer smaller than the actual header; treating a random packet (audio or ID header) as the tags packet.","solutions":["Verify the packet is the real OpusTags packet (starts with 'OpusTags') and pass the complete payload, not a truncated slice.","Check that the Ogg page was fully reassembled before parsing; handle logical-stream segmentation so payload length is not cut.","Guard at the call site with len(payload) >= 12 and errors.Is(err, ErrBadOpusTagsSignature) to skip non-tags packets."],"exampleFix":"// before\nheader, err := oggreader.ParseOpusTags(packet[:7]) // truncated slice\n// after\nif len(packet) >= 12 {\n    header, err = oggreader.ParseOpusTags(packet)\n}","handlingStrategy":"validation","validationCode":"const minOpusTagsLen = 12 // \"OpusTags\" magic + 4-byte vendor length\nif len(payload) >= minOpusTagsLen && string(payload[:8]) == \"OpusTags\" {\n    tags, err := oggreader.ParseOpusTags(payload)\n}","typeGuard":"func isPlausibleOpusTags(p []byte) bool {\n    return len(p) >= 12 && string(p[:8]) == \"OpusTags\"\n}","tryCatchPattern":"tags, err := oggreader.ParseOpusTags(payload)\nif errors.Is(err, oggreader.ErrBadOpusTagsSignature) {\n    // treat packet as non-tags / truncated; skip or reassemble\n} else if err != nil {\n    return err\n}","preventionTips":["Fully reassemble Ogg logical-stream packets (concatenate all pages) before parsing.","Check packet length (>= 12 bytes) and magic before calling ParseOpusTags.","Validate downloads/stream captures for completeness (checksum, final Ogg page flag).","Never parse fixed-size slices of a variable-length header."],"tags":["go","ogg","opus","truncated-input"],"backgroundTag":"payload-too-short","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"}