AlexxIT/go2rtc · error

hds: read buffer too small

Error message

hds: read buffer too small

What it means

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.

Solutions

  1. Increase the caller's read buffer size (frames can be large for video)
  2. Prefer WriteTo, which reads whole frames without buffering limits
  3. Negotiate smaller frame sizes at the HDS stream setup if possible
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/hap/hds/hds.go:101 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/eb08e0a0d88d677f. Report an issue: GitHub.

Appendix: source

Thrown at pkg/hap/hds/hds.go:101

	}

	nonce := make([]byte, hap.NonceSize)
	binary.LittleEndian.PutUint64(nonce, c.decryptCnt)
	c.decryptCnt++

	c.recv += n

	return chacha20poly1305.DecryptAndVerify(c.decryptKey, ciphertext[:0], nonce, ciphertext, verify)
}

func (c *Conn) Read(p []byte) (n int, err error) {
	b, err := c.read()
	if err != nil {
		return 0, err
	}
	n = copy(p, b)
	if len(b) > n {
		err = errors.New("hds: read buffer too small")
	}
	return
}

func (c *Conn) WriteTo(w io.Writer) (int64, error) {
	var total int64
	for {
		b, err := c.read()
		if err != nil {
			return total, err
		}

		n, err := w.Write(b)
		total += int64(n)
		if err != nil {
			return total, err
		}
	}

View on GitHub (pinned to c245815e75)