{"record":{"id":"555dc428afe42ea0","repo":"XTLS/Xray-core","slug":"insufficient-buffer","errorCode":null,"errorMessage":"insufficient buffer: ","messagePattern":"insufficient buffer: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"common/mux/frame.go","lineNumber":136,"sourceCode":"\t}\n\tif metaLen > 512 {\n\t\treturn errors.New(\"invalid metalen \", metaLen).AtError()\n\t}\n\n\tb := buf.New()\n\tdefer b.Release()\n\n\tif _, err := b.ReadFullFrom(reader, int32(metaLen)); err != nil {\n\t\treturn err\n\t}\n\treturn f.UnmarshalFromBuffer(b, readSourceAndLocal)\n}\n\n// UnmarshalFromBuffer reads a FrameMetadata from the given buffer.\n// Visible for testing only.\nfunc (f *FrameMetadata) UnmarshalFromBuffer(b *buf.Buffer, readSourceAndLocal bool) error {\n\tif b.Len() < 4 {\n\t\treturn errors.New(\"insufficient buffer: \", b.Len())\n\t}\n\n\tf.SessionID = binary.BigEndian.Uint16(b.BytesTo(2))\n\tf.SessionStatus = SessionStatus(b.Byte(2))\n\tf.Option = bitmask.Byte(b.Byte(3))\n\tf.Target.Network = net.Network_Unknown\n\n\tif f.SessionStatus == SessionStatusNew || (f.SessionStatus == SessionStatusKeep && b.Len() > 4 &&\n\t\tTargetNetwork(b.Byte(4)) == TargetNetworkUDP) { // MUST check the flag first\n\t\tif b.Len() < 8 {\n\t\t\treturn errors.New(\"insufficient buffer: \", b.Len())\n\t\t}\n\t\tnetwork := TargetNetwork(b.Byte(4))\n\t\tb.Advance(5)\n\n\t\taddr, port, err := addrParser.ReadAddressPort(nil, b)\n\t\tif err != nil {\n\t\t\treturn errors.New(\"failed to parse address and port\").Base(err)","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/common/mux/frame.go#L118-L154","documentation":"After reading the declared meta length from the wire, the buffer holds fewer than 4 bytes, yet a mux frame header needs at least sessionID(2) + status(1) + option(1). The length prefix and actual bytes disagree — truncated or corrupted metadata.","triggerScenarios":"A mux peer sending metaLen >= 1 but fewer than 4 bytes of body; mid-stream desynchronization after erroring frames; crafted/foreign data on the mux connection.","commonSituations":"Same roots as invalid metalen: mux pointed at non-mux server, connection cut mid-frame, or TLS/REALITY termination mismatch mangling the stream.","solutions":["Verify both ends run compatible Xray versions with matching mux settings.","Check for transparent proxies/CDNs in the path that could truncate or alter the stream.","Disable mux for that outbound to isolate whether framing or transport is at fault."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := frame.UnmarshalFromBuffer(b, false)\nif err != nil && strings.Contains(err.Error(), \"insufficient buffer\") {\n    closeMuxSession() // stream is corrupt; drop connection\n    return err\n}","preventionTips":["Guarantee atomic frame writes on the mux path so headers and bodies are never split/truncated.","Validate transport health (TLS/REALITY) before blaming mux framing."],"tags":["mux","protocol","framing","truncation","xray"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}