From d8994b7603d4a66910ac5d3cdb7d8af6c560f9bd Mon Sep 17 00:00:00 2001 From: ll11l1lIllIl1lll <88377095+ll11l1lIllIl1lll@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:52:34 +0000 Subject: [PATCH] Fix SplitHTTP H3 crash on v2rayNG (#3559) Fixes https://github.com/XTLS/Xray-core/issues/3556 --- transport/internet/splithttp/dialer.go | 29 ++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/transport/internet/splithttp/dialer.go b/transport/internet/splithttp/dialer.go index 9f98da3d..5c22f845 100644 --- a/transport/internet/splithttp/dialer.go +++ b/transport/internet/splithttp/dialer.go @@ -101,11 +101,32 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in if err != nil { return nil, err } - udpAddr, err := net.ResolveUDPAddr("udp", conn.RemoteAddr().String()) - if err != nil { - return nil, err + + var udpConn *net.UDPConn + var udpAddr *net.UDPAddr + + switch c := conn.(type) { + case *internet.PacketConnWrapper: + var ok bool + udpConn, ok = c.Conn.(*net.UDPConn) + if !ok { + return nil, errors.New("PacketConnWrapper does not contain a UDP connection") + } + udpAddr, err = net.ResolveUDPAddr("udp", c.Dest.String()) + if err != nil { + return nil, err + } + case *net.UDPConn: + udpConn = c + udpAddr, err = net.ResolveUDPAddr("udp", c.RemoteAddr().String()) + if err != nil { + return nil, err + } + default: + return nil, errors.New("unsupported connection type: %T", conn) } - return quic.DialEarly(ctx, conn.(*internet.PacketConnWrapper).Conn.(*net.UDPConn), udpAddr, tlsCfg, cfg) + + return quic.DialEarly(ctx, udpConn, udpAddr, tlsCfg, cfg) }, } downloadTransport = roundTripper