{"record":{"id":"13be8c45e5fc4d1c","repo":"AlexxIT/go2rtc","slug":"miss-packet-header-too-small","errorCode":null,"errorMessage":"miss: packet header too small","messagePattern":"miss: packet header too small","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/xiaomi/miss/client.go","lineNumber":231,"sourceCode":"\tswitch c.model {\n\tcase ModelDafang, ModelXiaofang, \"isa.camera.hlc6\":\n\t\treturn codecPCM\n\tcase \"chuangmi.camera.72ac1\":\n\t\treturn codecOPUS\n\t}\n\treturn 0\n}\n\nconst hdrSize = 32\n\nfunc (c *Client) ReadPacket() (*Packet, error) {\n\thdr, payload, err := c.Conn.ReadPacket()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"miss: read media: %w\", err)\n\t}\n\n\tif len(hdr) < hdrSize {\n\t\treturn nil, fmt.Errorf(\"miss: packet header too small\")\n\t}\n\n\tpayload, err = crypto.Decode(payload, c.key)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tpkt := &Packet{\n\t\tCodecID:  binary.LittleEndian.Uint32(hdr[4:]),\n\t\tSequence: binary.LittleEndian.Uint32(hdr[8:]),\n\t\tFlags:    binary.LittleEndian.Uint32(hdr[12:]),\n\t\tPayload:  payload,\n\t}\n\n\tswitch c.model {\n\tcase ModelDafang, ModelXiaofang, ModelLoockV2:\n\t\t// Dafang has ts in sec\n\t\t// LoockV2 has ts in msec for video, but zero ts for audio","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/xiaomi/miss/client.go#L213-L249","documentation":"ReadPacket expects every media packet header to be at least 32 bytes (hdrSize). A shorter header means the stream is corrupted, misaligned, or coming from an unexpected firmware/protocol version, so the packet is rejected rather than parsed.","triggerScenarios":"Calling ReadPacket when the transport returns a header shorter than 32 bytes — stream desynchronization after a partial read, protocol mismatch, or truncation bug in the transport layer.","commonSituations":"Connecting to a camera whose firmware emits a different packet layout; corrupted stream after a network hiccup; library/firmware version mismatch.","solutions":["Drop the bad packet and resynchronize the stream (reconnect or skip)","Update the library and camera firmware to matching versions","Check the transport layer for partial-read bugs that could split frames","Log the short header length to diagnose whether it is a systematic protocol mismatch"],"exampleFix":"// before\nfor { pkt, err := client.ReadPacket(); if err != nil { return err } } // aborts on one bad packet\n// after\nfor {\n    pkt, err := client.ReadPacket()\n    if err != nil {\n        if strings.Contains(err.Error(), \"header too small\") { continue } // skip corrupt packet\n        return err\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"pkt, err := client.ReadPacket()\nif err != nil {\n    if strings.Contains(err.Error(), \"header too small\") {\n        // skip/resync: reconnect or continue\n        continue\n    }\n    return err\n}","preventionTips":["Reconnect after any transport error to resynchronize the stream","Keep library and camera firmware versions compatible","Log header sizes to detect systematic protocol mismatches"],"tags":["miss","media-streaming","protocol"],"backgroundTag":"unexpected-response-shape","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}