{"record":{"id":"728496589d8bc940","repo":"chenhg5/cc-connect","slug":"yuanbao-length-d-exceeds-data-at-d","errorCode":null,"errorMessage":"yuanbao: length %d exceeds data at %d","messagePattern":"yuanbao: length (.+?) exceeds data at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/yuanbao/proto.go","lineNumber":160,"sourceCode":"\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)\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:","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/yuanbao/proto.go#L142-L178","documentation":"Thrown by parseFields when a length-delimited field declares a length (ln) that extends past the end of the available data: pos+ln > len(data). This means the message is internally inconsistent — the declared length cannot be satisfied — so the decoder aborts rather than produce a corrupt []byte.","triggerScenarios":"A wire-type-2 field whose length prefix says e.g. 500 bytes but only 30 remain; caused by byte-stream desynchronization (parser misaligned after a bad earlier field), corruption, or a truncated frame where the length varint survived but the payload did not. Also possible if a huge/corrupt length is parsed from garbage bytes.","commonSituations":"Merging raw TCP bytes into frames incorrectly, decoding a compressed/encrypted body as raw protobuf, server protocol change shifting field boundaries, or a malicious/corrupt upstream payload with a forged length.","solutions":["Verify frames are correctly delimited before decoding; do not feed a byte stream that may contain multiple or partial frames.","Log ln and pos plus a hex dump of data to check for desynchronization from an earlier misparse.","Confirm the payload is not compressed/encrypted — decompress/decrypt before parseFields.","If an earlier field parse could desync the cursor, validate the whole message with a stricter parser or resync from the frame boundary.","Check the yuanbao server version for wire-format changes."],"exampleFix":"// before\nbody := frame.Data // may contain header prefix\ncm, err := decodeConnMsg(body)\n// after\nif !frame.IsProtobufBody { // skip compressed/heartbeat frames\n    return nil\n}\ncm, err := decodeConnMsg(frame.Payload)\nif err != nil {\n    slog.Warn(\"yuanbao: bad frame, resyncing\", \"err\", err)\n    return nil\n}","handlingStrategy":"validation","validationCode":"func plausibleLength(b []byte, pos int) bool {\n    if pos >= len(b) { return false }\n    ln, n := decodeVarint(b[pos:])\n    return n > 0 && pos+n+int(ln) <= len(b)\n}","typeGuard":null,"tryCatchPattern":"fields, err := parseFields(data)\nif err != nil {\n    slog.Warn(\"yuanbao: overlong length field, resyncing\", \"err\", err)\n    stream.ResyncToNextFrame()\n    return\n}","preventionTips":["Verify payload is raw protobuf (decompress/decrypt first).","Hex-dump on failure to detect cursor desynchronization.","Sanity-check declared lengths (cap at a max message size) before trusting them.","Keep frame boundaries authoritative — restart parsing at frame starts only."],"tags":["protobuf","wire-format","corrupt-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"}