Repository navigation
Conversation
…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
force-pushed
the
fix/vision-reshape-oversize-buffer
branch
from
December 2, 2026 08:20
33fd000 to
ac2c8a9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
VisionWriterpanics when it receives a singleBufferlonger thanbuf.Size:Transports such as gRPC (
Hunk) hand a received chunk over as oneBuffercreated withbuf.NewExisted, so its length can exceedbuf.Size.ReshapeMultiBufferonly halves such a buffer once; the remainder can still be longer thanbuf.Size-21and gets truncated tobuf.Size.XtlsPaddingthen computespaddingLen = -21andExtendpanics, 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 thanbuf.Sizeintobuf.Size/2chunks before the existing reshape logic. Buffers withinbuf.Sizetake the unchanged path.Tests
proxy/proxy_reshape_test.go:TestReshapeMultiBufferOversizeBuffer: after reshape every buffer leaves room for padding and no data is lost (sizes frombuf.Size+1to 64 KiB).TestVisionWriterOversizeBufferNoPanic:VisionWriterwith 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.