{"record":{"id":"fd4170920dd522ca","repo":"pion/webrtc","slug":"invalid-nil-packet-fd4170","errorCode":null,"errorMessage":"invalid nil packet","messagePattern":"invalid nil packet","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/media/oggwriter/oggwriter.go","lineNumber":50,"sourceCode":"\tdefaultChannelCount                = 2\n\tchannelMappingFamily0              = 0\n\tchannelMappingFamily1              = 1\n\tchannelMappingFamily2              = 2\n\tchannelMappingFamily255            = 255\n\tidPageSignature                    = \"OpusHead\"\n\tcommentPageSignature               = \"OpusTags\"\n\tdefaultVendor                      = \"pion\"\n\tpageHeaderSignature                = \"OggS\"\n\tpageHeaderSize                     = 27\n\tmaxOggPageSegments                 = 255\n\tnoGranulePosition                  = ^uint64(0)\n\tmaxUint32Length                    = uint64(1<<32 - 1)\n)\n\nvar (\n\terrFileNotOpened        = errors.New(\"file not opened\")\n\terrOutputNotOpened      = errors.New(\"output not opened\")\n\terrInvalidNilPacket     = errors.New(\"invalid nil packet\")\n\terrDuplicateTrackSSRC   = errors.New(\"duplicate Ogg track SSRC\")\n\terrDuplicateTrackSerial = errors.New(\"duplicate Ogg track serial\")\n\terrTracksStarted        = errors.New(\"cannot add Ogg tracks after writing has started\")\n\terrPacketSSRCMismatch   = errors.New(\"RTP packet SSRC does not match Ogg track SSRC\")\n\terrInvalidOpusPacket    = errors.New(\"invalid Opus packet\")\n\terrInvalidChannelCount  = errors.New(\"invalid channel count\")\n\terrInvalidChannelMap    = errors.New(\"invalid channel mapping\")\n\terrInvalidOpusTags      = errors.New(\"invalid OpusTags\")\n)\n\ntype pageRewriter interface {\n\tio.Seeker\n\tio.WriterAt\n}\n\ntype writerConfig struct {\n\tsampleRate     uint32\n\tchannelMapping channelMapping","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/pion/webrtc/blob/8c25dc09fa9e7c09aac4309ead88093d760432b0/pkg/media/oggwriter/oggwriter.go#L32-L68","documentation":"errInvalidNilPacket is returned when a nil RTP packet is passed to a writer's WriteRTP-style method. Writers cannot serialize a nil packet, so they reject it up front. The same sentinel exists in both oggwriter and ivfwriter, and tests use it as the expected error for empty/nil packets.","triggerScenarios":"Calling WriteRTP(nil) on an Ogg/IVF writer; passing &rtp.Packet{} that the writer treats as invalid (ivfwriter_test.go:42 expects errInvalidNilPacket for an empty packet).","commonSituations":"A packet-producing loop forwards a nil packet after an upstream error, a channel of packets is closed and nil drained, track pipelines that emit placeholder packets.","solutions":["Skip nil packets before calling WriteRTP","Ensure the RTP packet is fully populated (header and payload) before writing","Fix upstream producers that emit nil packets on error paths"],"exampleFix":"// before\nwriter.WriteRTP(pkt) // pkt may be nil\n// after\nif pkt == nil || pkt.Payload == nil {\n    return nil // or log and skip\n}\nwriter.WriteRTP(pkt)","handlingStrategy":"validation","validationCode":"if pkt == nil || pkt.Header == nil {\n    return errors.New(\"cannot write nil RTP packet\")\n}\nerr := writer.WriteRTP(pkt)","typeGuard":"func isWritablePacket(pkt *rtp.Packet) bool {\n    return pkt != nil && pkt.Payload != nil\n}","tryCatchPattern":"if err := writer.WriteRTP(pkt); err != nil {\n    if errors.Is(err, oggwriter.ErrInvalidNilPacket) {\n        // skip and continue; do not treat as fatal\n        return nil\n    }\n    return err\n}","preventionTips":["Filter nil packets at the source of your packet channel","Check producer error paths that emit nil placeholders","Unit-test writer loops with nil inputs"],"tags":["rtp","validation","nil-argument","ogg","ivf"],"backgroundTag":"nil-rtp-packet","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"}