{"record":{"id":"ceb7c32769d54808","repo":"chenhg5/cc-connect","slug":"yuanbao-parse-length-at-d","errorCode":null,"errorMessage":"yuanbao: parse length at %d","messagePattern":"yuanbao: parse length at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/proto.go","lineNumber":156,"sourceCode":"\t\ttag, n := decodeVarint(data[pos:])\n\t\tif n == 0 {\n\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse varint tag failed at %d\", pos)\n\t\t}\n\t\tpos += n\n\t\tfieldNum := int(tag >> 3)\n\t\twt := int(tag & 0x07)\n\t\tswitch wt {\n\t\tcase wtVarint:\n\t\t\tval, n := decodeVarint(data[pos:])\n\t\t\tif n == 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse varint at %d\", pos)\n\t\t\t}\n\t\t\tfields = append(fields, field{fieldNum, wt, val})\n\t\t\tpos += n\n\t\tcase wtLen:\n\t\t\tln, n := decodeVarint(data[pos:])\n\t\t\tif n == 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: parse length at %d\", pos)\n\t\t\t}\n\t\t\tpos += n\n\t\t\tif pos+int(ln) > len(data) {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: length %d exceeds data at %d\", ln, pos)\n\t\t\t}\n\t\t\tval := make([]byte, ln)\n\t\t\tcopy(val, data[pos:pos+int(ln)])\n\t\t\tfields = append(fields, field{fieldNum, wt, val})\n\t\t\tpos += int(ln)\n\t\tcase wt64Bit:\n\t\t\tif pos+8 > len(data) {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: 64-bit truncated at %d\", pos)\n\t\t\t}\n\t\t\tfields = append(fields, field{fieldNum, wt, binary.LittleEndian.Uint64(data[pos : pos+8])})\n\t\t\tpos += 8\n\t\tcase wt32Bit:\n\t\t\tif pos+4 > len(data) {\n\t\t\t\treturn nil, fmt.Errorf(\"yuanbao: 32-bit truncated at %d\", pos)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L138-L174","documentation":"Thrown by parseFields when the length prefix of a length-delimited (wire type 2) field cannot be decoded as a varint at the current offset. decodeVarint returned n==0, meaning the buffer ends inside the length varint itself — the data ends before the field's length could even be read.","triggerScenarios":"A length-delimited field's tag was parsed but the length varint is incomplete: message truncated immediately after the tag, or a 10+ byte malformed length. Reached via any of the yuanbao decode entry points (decodeConnMsg, decodeAuthBindRsp, decodeInboundPush, decodeMsgBodyElement).","commonSituations":"Partial WebSocket frame delivery, incorrect frame reassembly, or feeding a sub-slice that cuts the message before its length-delimited fields.","solutions":["Ensure the complete frame is buffered before calling the decoder (check length header vs. bytes read).","Log the offset and byte dump to confirm where truncation occurs and fix the framing/reassembly code.","Reconnect and re-fetch the message; a truncated payload cannot be repaired locally.","Check for server protocol changes that may have introduced new/changed field encoding."],"exampleFix":"// before\npayload := buf[:n] // n = bytes read this tick\ncm, err := decodeConnMsg(payload)\n// after\nif n < expectedFrameLen {\n    return nil // wait for the rest of the frame\n}\ncm, err := decodeConnMsg(buf[:n])","handlingStrategy":"validation","validationCode":"if len(buf) < expectedFrameLen {\n    return nil // wait for remaining bytes before decoding\n}","typeGuard":null,"tryCatchPattern":"cm, err := decodeConnMsg(raw)\nif err != nil {\n    slog.Warn(\"yuanbao: incomplete frame\", \"err\", err)\n    return // frame will be re-requested after reconnect\n}","preventionTips":["Ensure the transport read loop accumulates the full frame before dispatch.","Compare bytes received against length-prefixed header values.","Treat truncation as a transport issue: reconnect, don't retry parse.","Test reassembly logic with deliberately split frames."],"tags":["protobuf","wire-format","truncated-data","yuanbao"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}