{"record":{"id":"eb08e0a0d88d677f","repo":"AlexxIT/go2rtc","slug":"hds-read-buffer-too-small","errorCode":null,"errorMessage":"hds: read buffer too small","messagePattern":"hds: read buffer too small","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hap/hds/hds.go","lineNumber":101,"sourceCode":"\t}\n\n\tnonce := make([]byte, hap.NonceSize)\n\tbinary.LittleEndian.PutUint64(nonce, c.decryptCnt)\n\tc.decryptCnt++\n\n\tc.recv += n\n\n\treturn chacha20poly1305.DecryptAndVerify(c.decryptKey, ciphertext[:0], nonce, ciphertext, verify)\n}\n\nfunc (c *Conn) Read(p []byte) (n int, err error) {\n\tb, err := c.read()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tn = copy(p, b)\n\tif len(b) > n {\n\t\terr = errors.New(\"hds: read buffer too small\")\n\t}\n\treturn\n}\n\nfunc (c *Conn) WriteTo(w io.Writer) (int64, error) {\n\tvar total int64\n\tfor {\n\t\tb, err := c.read()\n\t\tif err != nil {\n\t\t\treturn total, err\n\t\t}\n\n\t\tn, err := w.Write(b)\n\t\ttotal += int64(n)\n\t\tif err != nil {\n\t\t\treturn total, err\n\t\t}\n\t}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/hap/hds/hds.go#L83-L119","documentation":"HDS (HomeKit Data Stream) Read guard: a decrypted record was successfully read, but it is larger than the caller-provided buffer p, so copy() truncated it. The error flags data loss rather than a protocol failure — the consumer buffer must be at least as large as the largest frame the peer sends.","triggerScenarios":"Thrown at pkg/hap/hds/hds.go:101 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Increase the caller's read buffer size (frames can be large for video)","Prefer WriteTo, which reads whole frames without buffering limits","Negotiate smaller frame sizes at the HDS stream setup if possible"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}