{"record":{"id":"fc67f77d76fa9ed5","repo":"XTLS/Xray-core","slug":"read-minecraft-custom-payload-data-w","errorCode":null,"errorMessage":"read minecraft custom payload data: %w","messagePattern":"read minecraft custom payload data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"transport/internet/finalmask/xmc/packet_stream.go","lineNumber":156,"sourceCode":"func (s *packetStream) remoteCustomPayloadID() int {\n\tif s.isClient {\n\t\treturn configurationClientboundCustomPayload\n\t}\n\treturn configurationServerboundCustomPayload\n}\n\nfunc parseCustomPayload(packet *mcPacket) ([]byte, bool, error) {\n\tr := bytes.NewReader(packet.data)\n\tvar channel String\n\tif err := channel.readFrom(r); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"read minecraft custom payload channel: %w\", err)\n\t}\n\tif string(channel) != packetChannel {\n\t\treturn nil, false, nil\n\t}\n\tpayload := make([]byte, r.Len())\n\tif _, err := io.ReadFull(r, payload); err != nil {\n\t\treturn nil, false, fmt.Errorf(\"read minecraft custom payload data: %w\", err)\n\t}\n\treturn payload, true, nil\n}\n\nfunc (s *packetStream) writeKeepAlive(id Long) error {\n\ts.writeMu.Lock()\n\tdefer s.writeMu.Unlock()\n\tif err := writePacket(s.writer, configurationKeepAlive, &id); err != nil {\n\t\treturn fmt.Errorf(\"write minecraft keep-alive: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (s *packetStream) keepAliveLoop() {\n\tticker := time.NewTicker(keepAlivePeriod)\n\tdefer ticker.Stop()\n\tfor {\n\t\tselect {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/packet_stream.go#L138-L174","documentation":"parseCustomPayload failed to read the payload bytes after the channel String with io.ReadFull. Because the reader is an in-memory bytes.Reader over the already-received packet data and the slice is sized to r.Len(), this error is effectively unreachable; hitting it indicates an internal bug in packet handling rather than a network problem.","triggerScenarios":"A custom-payload packet on channel \"xmc:data\" whose trailing byte count does not match expectations due to a bug in readPacket/mcPacket handling, or a fork that changed how packet.data is populated.","commonSituations":"Patches to mcPacket that truncate packet.data; custom builds altering parseCustomPayload; not observed in stock code paths.","solutions":["If maintaining a fork, verify packet.data passed to parseCustomPayload is the complete undecoded body","Report upstream with a packet hex dump if it reproduces on unmodified code","No runtime workaround exists; the error is defensive"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"n, err := stream.Read(buf)\nif err != nil && strings.Contains(err.Error(), \"custom payload data\") {\n    // internal invariant: report with full context and close\n    return fmt.Errorf(\"xmc internal decode bug: %w\", err)\n}","preventionTips":["Keep mcPacket parsing and parseCustomPayload in sync when patching","Add fuzz tests over parseCustomPayload to catch body-handling regressions"],"tags":["go","minecraft","internal","decode"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}