{"record":{"id":"2621388b600ab519","repo":"AlexxIT/go2rtc","slug":"av-login-too-short-d-bytes","errorCode":null,"errorMessage":"av login too short: %d bytes","messagePattern":"av login too short: (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/tutk/dtls/conn_dtls.go","lineNumber":255,"sourceCode":"\t\tfmt.Printf(\"[SERVER] Waiting for AV Login request from camera...\\n\")\n\t}\n\n\t// Wait for AV Login request from camera\n\tbuf := make([]byte, 1024)\n\tconn.SetReadDeadline(time.Now().Add(5 * time.Second))\n\tn, err := conn.Read(buf)\n\tif err != nil {\n\t\tgo conn.Close()\n\t\treturn fmt.Errorf(\"read av login: %w\", err)\n\t}\n\n\tif c.verbose {\n\t\tfmt.Printf(\"[SERVER] AV Login request len=%d data:\\n%s\", n, hexDump(buf[:n]))\n\t}\n\n\tif n < 24 {\n\t\tgo conn.Close()\n\t\treturn fmt.Errorf(\"av login too short: %d bytes\", n)\n\t}\n\n\tchecksum := binary.LittleEndian.Uint32(buf[20:])\n\tresp := c.msgAVLoginResponse(checksum)\n\n\tif c.verbose {\n\t\tfmt.Printf(\"[SERVER] Sending AV Login response: %d bytes\\n\", len(resp))\n\t}\n\n\tif _, err = conn.Write(resp); err != nil {\n\t\tgo conn.Close()\n\t\treturn fmt.Errorf(\"write av login response: %w\", err)\n\t}\n\n\tif c.verbose {\n\t\tfmt.Printf(\"[SERVER] AV Login response sent, waiting for possible resend...\\n\")\n\t}\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/tutk/dtls/conn_dtls.go#L237-L273","documentation":"AVServStart validates the received AV login request is at least 24 bytes so it can read the checksum at offset 20. If the packet is shorter, the library refuses to parse it and closes the connection. It indicates a malformed or unexpected AV login packet from the camera.","triggerScenarios":"StartIntercom -> AVServStart when the first packet received after the DTLS handshake is smaller than 24 bytes — e.g. a DTLS control artifact, a partial read, or a non-AV-login message arriving first.","commonSituations":"Firmware protocol mismatch (older/newer camera sending a different login layout); fragmentation causing a short first read; wrong channel receiving unexpected data.","solutions":["Log the raw bytes (hexDump) and compare with the expected AV login layout","Check camera firmware version vs the protocol version this library implements","Buffer/coalesce reads until at least 24 bytes are available if the transport fragments packets","Verify you are reading on the correct channel (iotcChannelBack)"],"exampleFix":"// before\nif n < 24 {\n\tgo conn.Close()\n\treturn fmt.Errorf(\"av login too short: %d bytes\", n)\n}\n// after\nfor n < 24 {\n\tm, err := conn.Read(buf[n:])\n\tif err != nil {\n\t\tgo conn.Close()\n\t\treturn fmt.Errorf(\"av login too short after re-read: %d bytes: %w\", n, err)\n\t}\n\tn += m\n}","handlingStrategy":"validation","validationCode":"// after read: validate before use\nif n < 24 {\n\t// accumulate more reads or treat as protocol error\n}","typeGuard":"func isValidAVLogin(buf []byte, n int) bool {\n\treturn n >= 24\n}","tryCatchPattern":"if err := conn.AVServStart(); err != nil {\n\tif strings.Contains(err.Error(), \"av login too short\") {\n\t\t// log hexDump, check firmware compatibility\n\t}\n}","preventionTips":["Pin library version to camera firmware protocol generation","Log raw login packets when debugging protocol mismatches","Read until the full login frame is available if transport fragments","Validate channel selection matches the login traffic"],"tags":["protocol","validation","packet","intercom"],"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"}