Skip to content

Vision: split oversized buffers before reshape to avoid XtlsPadding panic - #7547

Closed
dewil wants to merge 1 commit into
XTLS:mainfrom
dewil:fix/vision-reshape-oversize-buffer
Closed

dewil wants to merge 1 commit into
XTLS:mainfrom
dewil:fix/vision-reshape-oversize-buffer

Conversation

@dewil

@dewil dewil commented Dec 2, 2026 •

Copy link
Copy Markdown

Problem

VisionWriter panics when it receives a single Buffer longer than buf.Size:

panic: runtime error: slice bounds out of range [8192:8171]
github.com/xtls/xray-core/common/buf.(*Buffer).Extend
github.com/xtls/xray-core/proxy.XtlsPadding (proxy/proxy.go)
github.com/xtls/xray-core/proxy.(*VisionWriter).WriteMultiBuffer
github.com/xtls/xray-core/common/buf.copyInternal

Transports such as gRPC (Hunk) hand a received chunk over as one Buffer created with buf.NewExisted, so its length can exceed buf.Size. ReshapeMultiBuffer only halves such a buffer once; the remainder can still be longer than buf.Size-21 and gets truncated to buf.Size. XtlsPadding then computes paddingLen = -21 and Extend panics, taking the whole process down.

We hit it in production on relays where clients connect over VLESS+gRPC and the outbound is VLESS+REALITY with flow: xtls-rprx-vision. Clients that send gRPC hunks larger than 8192 bytes (sing-box based ones) crashed the core several times per minute. Native Xray clients do not send such hunks, so the issue is easy to miss. Reproduced on v26.10.31 and on current main.

Fix

In ReshapeMultiBuffer, split buffers longer than buf.Size into buf.Size/2 chunks before the existing reshape logic. Buffers within buf.Size take the unchanged path.

Tests

proxy/proxy_reshape_test.go:

  • TestReshapeMultiBufferOversizeBuffer: after reshape every buffer leaves room for padding and no data is lost (sizes from buf.Size+1 to 64 KiB).
  • TestVisionWriterOversizeBufferNoPanic: VisionWriter with 16/24/64 KiB single buffers does not panic.

Both tests fail without the change (no room for padding / slice bounds out of range [8192:8171]) and pass with it. go test ./proxy/... ./common/buf/... passes.

…anic

Transports such as gRPC (Hunk) hand a received chunk over as a single
Buffer created with buf.NewExisted, so its length can exceed buf.Size.
ReshapeMultiBuffer only halves such a buffer once, so the remainder can
still be longer than buf.Size-21 and is silently truncated to buf.Size.
XtlsPadding then computes a negative padding length and Extend(-21)
panics:

  panic: runtime error: slice bounds out of range [8192:8171]
  common/buf.(*Buffer).Extend
  proxy.XtlsPadding
  proxy.(*VisionWriter).WriteMultiBuffer

Seen on a relay where clients connect over gRPC and the outbound uses
VLESS+REALITY with flow xtls-rprx-vision: clients that send gRPC hunks
larger than 8192 bytes (sing-box based ones) crash the whole process.

Split buffers longer than buf.Size into buf.Size/2 chunks first. Adds
tests for ReshapeMultiBuffer and VisionWriter with oversized buffers.
@dewil
dewil force-pushed the fix/vision-reshape-oversize-buffer branch from 33fd000 to ac2c8a9 Compare December 2, 2026 08:20
@Fangliding Fangliding closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants