pion/webrtc · error

malformed rtpdump

Error message

malformed rtpdump

What it means

errMalformed is the sentinel for structural corruption of an rtpdump file, returned by rtpdump.NewReader when the input is not a valid RTPDump: fewer than 36 bytes available for the preamble (EOF on peek/read), the preamble does not match the required "#!rtpplay1.0 address/port\n" regular expression, or the 16-byte binary header is truncated (unexpected EOF). The offending input is any stream that is not a complete rtpplay1.0 recording.

Source

Thrown at pkg/media/rtpdump/rtpdump.go:21

func NewReader(r io.Reader) (*Reader, Header, error) {
	var hdr Header

	bio := bufio.NewReader(r)

	// Look ahead to see if there's a valid preamble
	peek, err := bio.Peek(preambleLen)
	if errors.Is(err, io.EOF) {
		return nil, hdr, errMalformed
	}
	if err != nil {
		return nil, hdr, err
	}

	// The file starts with #!rtpplay1.0 address/port\n
	preambleRegexp := regexp.MustCompile(`#\!rtpplay1\.0 \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,5}\n`)
	if !preambleRegexp.Match(peek) {
		return nil, hdr, errMalformed
	}

	// consume the preamble
	_, _, err = bio.ReadLine()
	if errors.Is(err, io.EOF) {
		return nil, hdr, errMalformed
	}
	if err != nil {
		return nil, hdr, err
	}

	hBuf := make([]byte, headerLen)
	_, err = io.ReadFull(bio, hBuf)
	if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) {
		return nil, hdr, errMalformed

View on GitHub (pinned to 8c25dc09fa)

Solutions

  1. Verify the file is a genuine rtpdump starting with the #!rtpplay1.0 address/port preamble line
  2. Check the file is not truncated; regenerate or re-download the recording
  3. Capture the file again with the original rtpdump tool instead of hand-editing it
  4. Use errors.Is(err, rtpdump.ErrMalformed) to distinguish bad input from transient I/O errors
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/media/rtpdump/rtpdump.go:21 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of pion/webrtc@8c25dc09fa (2026-09-03). Data as JSON: /api/errors/0c14d55a1450e358. Report an issue: GitHub.