Skip to content

fix MultiBuffer Compact function#5014

Closed
patterniha wants to merge 1 commit intoXTLS:mainfrom
patterniha:fix-wow
Closed

fix MultiBuffer Compact function#5014
patterniha wants to merge 1 commit intoXTLS:mainfrom
patterniha:fix-wow

Conversation

@patterniha
Copy link
Collaborator

@patterniha patterniha commented Aug 11, 2025

Unfortunately, the lack of error return in the two functions read and write (in buffer.go) caused the author to write the function Compact (in multi_buffer.go) incorrectly and no one has noticed until now.

///

common.Must2(last.ReadFrom(curr)) does not necessarily append curr to last, also common.Must2 has no effect here, because ReadFrom does not return any error on failure.

///

for example suppose:

in Compact function for loop, last == mb[0] and curr == mb[1]
and last.start == 2 and last.end == 8192
and curr.start == 0 and curr.end == 2
so last.Len() + curr.Len() <= 8192
but common.Must2(last.ReadFrom(curr)) doesn't actually do anything!!!

///

Compact function is used in tls and websocket, and this caused the Xray-core to occasionally send corrupted data for almost all users!!! Whoa!!!

thanks to @Vdu6n1XMrq6694a8 for his/her great Reproduction.

@patterniha

This comment was marked as outdated.

@Fangliding
Copy link
Member

Fangliding commented Aug 11, 2025

buf最好别动 只是 Compact 函数的问题 还是我来修吧

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