{"record":{"id":"ff988ed1b7afce4d","repo":"chenhg5/cc-connect","slug":"yuanbao-32-bit-truncated-at-d","errorCode":null,"errorMessage":"yuanbao: 32-bit truncated at %d","messagePattern":"yuanbao: 32-bit truncated at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/proto.go","lineNumber":174,"sourceCode":"\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)\n\t\t\t}\n\t\t\tfields = append(fields, field{fieldNum, wt, uint64(binary.LittleEndian.Uint32(data[pos : pos+4]))})\n\t\t\tpos += 4\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"yuanbao: unknown wire type %d at %d\", wt, pos)\n\t\t}\n\t}\n\treturn fields, nil\n}\n\nfunc decodeVarint(data []byte) (uint64, int) {\n\tvar result uint64\n\tvar shift uint\n\tfor i, b := range data {\n\t\tresult |= uint64(b&0x7F) << shift\n\t\tshift += 7\n\t\tif b&0x80 == 0 {\n\t\t\treturn result, i + 1","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L156-L192","documentation":"Thrown by parseFields when a 32-bit fixed-width field (wire type 5, wt32Bit) is present but fewer than 4 bytes remain in the buffer (pos+4 > len(data)). The decoder refuses to read a partial fixed32 value, indicating message truncation or cursor desynchronization.","triggerScenarios":"A frame ending in a fixed32 field (e.g. a float or checksum) arrives short by 1–3 bytes; or trailing garbage after a truncated frame is misread as a wt32Bit tag. Reached via decodeConnMsg, decodeAuthBindRsp, decodeInboundPush, decodeMsgBodyElement.","commonSituations":"Frame reassembly bug dropping trailing bytes, proxy truncating long messages, or the parser consuming wrong byte counts earlier in the message (e.g. a wire type unsupported earlier caused misalignment).","solutions":["Confirm the byte count read from the transport matches the frame's declared length before decoding.","Hex-dump the tail of the failing buffer to see whether real data was cut or garbage was appended; fix the framing code accordingly.","Resync the connection (reconnect) after a malformed frame instead of continuing to parse the stream.","Audit parseFields for any code path that advances pos by the wrong amount, which desyncs later fixed32 fields."],"exampleFix":"// before\nmsg := make([]byte, declared)\ncopy(msg, buf)\ncm, err := decodeConnMsg(msg)\n// after\nif len(buf) < declared {\n    return nil // incomplete frame; wait for remaining bytes\n}\ncm, err := decodeConnMsg(buf[:declared])","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func hasFixed32(b []byte, pos int) bool { return pos+4 <= len(b) }","tryCatchPattern":"cm, err := decodeConnMsg(raw)\nif err != nil {\n    slog.Warn(\"yuanbao: truncated fixed32, dropping frame\", \"err\", err)\n    return\n}","preventionTips":["Verify read byte counts match frame headers before decoding.","Beware of code paths advancing pos by wrong amounts — audit cursor arithmetic.","Resync the stream after the first malformed frame.","Include fixed32 tail fields in codec tests."],"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-14T05:17:10.506Z"}