{"record":{"id":"beea2ba6de110406","repo":"probelabs/goreplay","slug":"capture-length-d-does-not-match-data-length-d","errorCode":null,"errorMessage":"capture length %d does not match data length %d","messagePattern":"capture length (.+?) does not match data length (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/capture/dump.go","lineNumber":116,"sourceCode":"func (w *Writer) writePacketHeader(ci gopacket.CaptureInfo) error {\n\tt := ci.Timestamp\n\tif t.IsZero() {\n\t\tt = time.Now()\n\t}\n\tsecs := t.Unix()\n\tusecs := t.Nanosecond() / w.tsScaler\n\tbinary.LittleEndian.PutUint32(w.buf[0:4], uint32(secs))\n\tbinary.LittleEndian.PutUint32(w.buf[4:8], uint32(usecs))\n\tbinary.LittleEndian.PutUint32(w.buf[8:12], uint32(ci.CaptureLength))\n\tbinary.LittleEndian.PutUint32(w.buf[12:16], uint32(ci.Length))\n\t_, err := w.w.Write(w.buf[:])\n\treturn err\n}\n\n// WritePacket writes the given packet data out to the file.\nfunc (w *Writer) WritePacket(ci gopacket.CaptureInfo, data []byte) error {\n\tif ci.CaptureLength != len(data) {\n\t\treturn fmt.Errorf(\"capture length %d does not match data length %d\", ci.CaptureLength, len(data))\n\t}\n\tif ci.CaptureLength > ci.Length {\n\t\treturn fmt.Errorf(\"invalid capture info %+v:  capture length > length\", ci)\n\t}\n\tif err := w.writePacketHeader(ci); err != nil {\n\t\treturn fmt.Errorf(\"error writing packet header: %v\", err)\n\t}\n\t_, err := w.w.Write(data)\n\treturn err\n}\n","sourceCodeStart":98,"sourceCodeEnd":127,"githubUrl":"https://github.com/probelabs/goreplay/blob/251e45abd242886bb64ff2b2dc98789556b56330/internal/capture/dump.go#L98-L127","documentation":"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.","triggerScenarios":"Thrown at internal/capture/dump.go:116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Find the source producing CaptureInfo with wrong CaptureLength versus data length","Check for data truncation or buffer reuse bugs upstream in the capture path","Skip/re-record the affected capture instead of writing corrupt output"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"251e45abd242886bb64ff2b2dc98789556b56330","analyzedAt":"2026-09-02T16:44:11.369Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}