probelabs/goreplay · error

capture length %d does not match data length %d

Error message

capture length %d does not match data length %d

What it means

Writer.WritePacket sanity check: the gopacket.CaptureInfo's CaptureLength must equal the actual packet byte slice length being written; a mismatch means corrupt/inconsistent capture metadata, so the packet is rejected rather than writing a malformed pcap record.

Source

Thrown at internal/capture/dump.go:116

func (w *Writer) writePacketHeader(ci gopacket.CaptureInfo) error {
	t := ci.Timestamp
	if t.IsZero() {
		t = time.Now()
	}
	secs := t.Unix()
	usecs := t.Nanosecond() / w.tsScaler
	binary.LittleEndian.PutUint32(w.buf[0:4], uint32(secs))
	binary.LittleEndian.PutUint32(w.buf[4:8], uint32(usecs))
	binary.LittleEndian.PutUint32(w.buf[8:12], uint32(ci.CaptureLength))
	binary.LittleEndian.PutUint32(w.buf[12:16], uint32(ci.Length))
	_, err := w.w.Write(w.buf[:])
	return err
}

// WritePacket writes the given packet data out to the file.
func (w *Writer) WritePacket(ci gopacket.CaptureInfo, data []byte) error {
	if ci.CaptureLength != len(data) {
		return fmt.Errorf("capture length %d does not match data length %d", ci.CaptureLength, len(data))
	}
	if ci.CaptureLength > ci.Length {
		return fmt.Errorf("invalid capture info %+v:  capture length > length", ci)
	}
	if err := w.writePacketHeader(ci); err != nil {
		return fmt.Errorf("error writing packet header: %v", err)
	}
	_, err := w.w.Write(data)
	return err
}

View on GitHub (pinned to 251e45abd2)

Solutions

  1. Find the source producing CaptureInfo with wrong CaptureLength versus data length
  2. Check for data truncation or buffer reuse bugs upstream in the capture path
  3. Skip/re-record the affected capture instead of writing corrupt output
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/capture/dump.go:116 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of probelabs/goreplay@251e45abd2 (2026-09-02). Data as JSON: /api/errors/beea2ba6de110406. Report an issue: GitHub.